常用的Java加密技术和核心代码系列:
Base64以及关于Base64遇到的坑 https://blog.csdn.net/haponchang/article/details/106094115
消息摘要算法 https://blog.csdn.net/haponchang/article/details/106096542
对称加密(DES、3DES、AES、PBE) https://blog.csdn.net/haponchang/article/details/106096766
非对称加密(RSA、DH) https://blog.csdn.net/haponchang/article/details/106097998
数字签名证书 https://blog.csdn.net/haponchang/article/details/106098779
使用Base64
public String encode(String src)
{
byte[] encodeBytes = Base64.getEncoder().encode(src.getBytes());
return new String(encodeBytes);
}
public String decode(String src)
{
byte[] decodeBytes = Base64.getDecoder().decode(src.getBytes());
return new String(decodeBytes);
}
Base64编码对应关系表
使用Base64可能遇到的坑
1,编码格式问题,encode或decode是getBytes()的编码不一致导致结果不一致
public class Base64Strategy {
public String encode(String src) throws UnsupportedEncodingException {
byte[] encodeBytes = Base64.getEncoder (