java调用的base64jar包是commons-codec-1.4.jar
加密
base64加密方法:1> byte[] bytes = Base64.encodeBase64("content");
2> String str = Base64.encodeBase64String("content");
解密
byte[] bytes = Base64.decodeBase64("content");
问题1:
encodeBase64String方法获取到的字符串带\r\n,这个如果用在其他rsa或者ecc加密中会很麻烦;
解决方案1:使用new String(Base64.encodeBase64("content"))代替encodeBase64String即:String str = new String(Base64.encodeBase64("content"))
解决方案2:使用replaceAll("\r\n","")即String str = Base64.encodeBase64String("content").replaceAll("\r\n","")
转自:
https://blog.csdn.net/u014745604/article/details/81626581