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); }
原文链接:https://blog.csdn.net/2302_78041478/article/details/130564992
发表评论