import java.io.IOException
import sun.misc.BASE64Decoder
import sun.misc.BASE64Encoder
public class Test {
public static void main(String[] args) {
String str = "java12345"
String ret = null
ret = new BASE64Encoder().encode(str.getBytes())
System.out.println("加密前:"+str+" 加密后:"+ret)
str = "amF2YTEyMzQ1"
try {
ret = new String(new BASE64Decoder().decodeBuffer(str))
} catch (IOException e) {
e.printStackTrace()
}
System.out.println("解密前:"+str+" 解密后:"+ret)
}
}
/** * BASE64解密 * * @param key * @return * @throws Exception */public static byte[] decryptBASE64(String key) throws Exception { return (new BASE64Decoder()).decodeBuffer(key)} /** * BASE64加密 * * @param key * @return * @throws Exception */ public static String encryptBASE64(byte[] key) throws Exception { return (new BASE64Encoder()).encodeBuffer(key)}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)