⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 criptografiautil.java

📁 Example: How to do Base64 Encryption and Decryption
💻 JAVA
字号:
import java.security.MessageDigest;

import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
/*
   For more information http://en.wikipedia.org/wiki/Base64
    Remember 
	The sun.* packages are not part of the supported, public interface.
	A Java program that directly calls into sun.* packages is not guaranteed to work on all Java-compatible platforms. In fact, such a program is not guaranteed to work even in future versions on the same platform.
	http://java.sun.com/products/jdk/faq/faq-sun-packages.html
*/

public class CriptografiaUtil {
	public static String criptografar(String original) {
		if (original != null)
			return new BASE64Encoder().encode(original.getBytes());
		else
			return original;
	}

	public static String descriptografar(String codificado) {
		try {
			if (codificado != null)
				return new String(new BASE64Decoder().decodeBuffer(codificado));
		} catch (Exception e) {
		}
		return codificado;
	}

	
	public static void main(String args[]) {
		String unicsul = "unicsul";
		String encriptografado = null;
		
		encriptografado = criptografar(unicsul);
		
		System.out.println(encriptografado);

		System.out.println(descriptografar(encriptografado));
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -