- Base64算法
消息摘要算法
对称加密
- DES
- AES
- 非对称加密
###Base64
- 概述
- java中加解密的包有:
- java.security : -消息摘要
- javax.crypto : -安全消息摘要,消息认证码
- java.net.ssl : -安全套接字
- Bouncy Castle 第三方扩展加解密包 (可以配置和调用)
- Commons Codec (Apache提供)
- Base64 , 二进制 十六进制,字符集 编码
- URL编辑 ,URL解码
- java中加解密的包有:
实现
JDK 实现Base64
/** * JDK 实现Base64编码 * @param src * @return */ public static String jdkBase64Encode(String src){ String result = null; BASE64Encoder base64Encoder = new BASE64Encoder(); result = base64Encoder.encode(src.getBytes()); return result ; } /** * JDK 实现Base64解码 * @param code * @return * @throws IOException */ public static String jdkBase64Decode(String code) throws IOException{ BASE64Decoder decoder = new BASE64Decoder(); byte[] bytes = decoder.decodeBuffer(code); return new String(bytes); }
Commons-Codec 实现
/** * CommonsCodec 实现Base64编码 * @param src * @return */ public static String commonsCodecBase64Encode(String src){ byte[] bytes = Base64.encodeBase64(src.getBytes()); return new String(bytes) ; } /** * CommonsCodec 实现Base64解码 * @param code * @return */ public static String commonsCodecBase64Decode(String code){ byte[] bytes = Base64.decodeBase64(code.getBytes()); return new String(bytes) ; }
Buncy Castle 实现
/** * Bouncy Castle 实现Base64编码 * @param src * @return */ public static String bcBase64Encode(String src){ byte[] bytes = org.bouncycastle.util.encoders.Base64.encode(src.getBytes()); return new String(bytes) ; } /** * Bouncy Castle 实现Base64解码 * @param src * @return */ public static String bcBase64Decode(String src){ byte[] bytes = org.bouncycastle.util.encoders.Base64.decode(src.getBytes()); return new String(bytes) ; }