加密方式
对称加密
非对称加密
散列函数 md5 哈希 主要用于验证
数据签名 (非对称加密的具体应用)
java安全组成
图片.png
摘要:1.修改JDK的配置文件:%JDK_HOME%jrelibsecurityjava.security//加上security.provider.10=org.bouncycastle.jce.provider.BouncyCastleProvider 2.在代码里直接添加Security.addProvider(neworg.bouncycastle.jce.provider.BouncyCastleProvider());
jdk提供的相关类
图片.png
案例
package com.alan;
import java.util.Base64;
public class Base64Test {
//定义要加密的字符串
private static String src = "imooc security base64";
public static void main(String[] args) {
bouncyCastleBase64();
}
//jdk方式加密
public static void jdkBase64(){
Base64.Encoder encoder = Base64.getEncoder();
String s = encoder.encodeToString(src.getBytes());
System.out.println("加密:"+s);
Base64.Decoder decoder = Base64.getDecoder();
System.out.println("解密"+ new String(decoder.decode(s)));
}
//commons codec
public static void commonsCodesBase64(){
byte[] bytes = org.apache.commons.codec.binary.Base64.encodeBase64(src.getBytes());
System.out.println("加密:"+new String(bytes));
byte[] bytes1 = org.apache.commons.codec.binary.Base64.decodeBase64(bytes);
System.out.println("解密:"+ new String(bytes1));
}
//bouncyCastleBase64
public static void bouncyCastleBase64(){
byte[] encode = org.bouncycastle.util.encoders.Base64.encode(src.getBytes());
System.out.println("加密1:"+new String(encode));
byte[] decode = org.bouncycastle.util.encoders.Base64.decode(encode);
System.out.println("解密1:"+ new String(decode));
}
}