java实现Base64加解密
@Test
public void test01() throws Exception {
String name = "LuWenMenHu";
String passWord = "pswd123456";
StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append(name).append("&").append(passWord);
String str = new String(stringBuffer);
byte[] b = str.getBytes("UTF-8");
Base64 base64 = new Base64();
String base64Encode = new String(base64.encode(b));
System.out.println("base64加密:" + base64Encode.toString());
String base64Decode = new String(new Base64().decode(base64Encode), "UTF-8");
System.out.println("base64解密:" + base64Decode.toString());
}
打印结果
------------start ----------------------------
base64加密:THVXZW5NZW5IdSZwc3dkMTIzNDU2
base64解密:LuWenMenHu&pswd123456
------------end ----------------------------