base64加密解密遇到的换行问题

Java Base64 加密解密详解
本文详细介绍了在Java中使用commons-codec-1.4.jar进行Base64加密和解密的方法,包括如何避免加密字符串中出现 字符的问题,并提供了两种解决方案。

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 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值