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","")
转自:
Java Base64 加密解密详解
本文详细介绍了在Java中使用commons-codec-1.4.jar进行Base64加密和解密的方法,包括如何避免加密字符串中出现
字符的问题,并提供了两种解决方案。
1451

被折叠的 条评论
为什么被折叠?



