MD5和DES的加密解密代码:
public static void testEncryption(){
//加密工具
StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();
//加密配置
EnvironmentStringPBEConfig config = new EnvironmentStringPBEConfig();
//加密算法,写死即可
config.setAlgorithm("PBEWithMD5AndDES");
//加密使用salt设置
config.setPassword("sad124f1f1rf1fgt5");
//应用配置
encryptor.setConfig(config);
//需要加密数据
String plaintext="XC_2022Test836";
//加密
String encrypttext=encryptor.encrypt(plaintext);
System.out.println(plaintext + " : " + encrypttext);
}
//解密
public static void testDecryption(){
//加密工具
StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();
//加密配置
EnvironmentStringPBEConfig config = new EnvironmentStringPBEConfig();
//加密算法,写死即可
config.setAlgorithm("PBEWithMD5AndDES");
//加密使用salt设置
config.setPassword("*********");
//应用配置
encryptor.setConfig(config);
//需要加密数据
String encrypttext="*********";
//加密
String plaintext=encryptor.decrypt(encrypttext);
System.out.println(encrypttext + " : " + plaintext);
}