Base64算法实现:可以将任意的字节数组数据,通过算法,生成只有(大小写英文、数字、+、/)(一共64个字符)内容表示的字符串数据。
private static final String str = "鲤鱼精";
-JDK实现
BASE64Encoder encoder = new BASE64Encoder();
String encode = encoder.encode(str.getBytes());
System.out.println("encode:" + encode);
BASE64Decoder decoder = new BASE64Decoder();
System.out.println("decode:"+new String(decoder.decodeBuffer(encode)));
-Commons Codes实现
byte[] encode = Base64.encodeBase64(str.getBytes());
System.out.println("encode:"+new String(encode));
byte[] decode = Base64.decodeBase64(encode);
System.out.println("decode:"+new String(decode));
-Bouncy Castle实现
byte[] encode = org.bouncycastle.util.encoders.Base64.encode(str.getBytes());
System.out.println("encode:"+new String(encode));
byte[] decode = org.bouncycastle.util.encoders.Base64.decode(encode);
System.out.println("decode:"+new String(decode));
使用场景:e-mail 密钥 短文本
JAVA加解密案例源码地址:http://download.csdn.net/detail/jacxuan/9774737