@Test
public void testEncrypt() throws Exception {
StandardPBEStringEncryptor standardPBEStringEncryptor = new StandardPBEStringEncryptor();
EnvironmentPBEConfig config = new EnvironmentPBEConfig();
config.setAlgorithm("PBEWithMD5AndDES"); // 加密的算法,这个算法是默认的
config.setPassword("ljk"); // 加密的密钥
standardPBEStringEncryptor.setConfig(config);
String plainText = "linjingke";
String encryptedText = standardPBEStringEncryptor.encrypt(plainText);
System.out.println(encryptedText);
}
@Test
public void testDe() throws Exception {
StandardPBEStringEncryptor standardPBEStringEncryptor = new StandardPBEStringEncryptor();
EnvironmentPBEConfig config = new EnvironmentPBEConfig();
config.setAlgorithm("PBEWithMD5AndDES");
config.setPassword("ljk");
standardPBEStringEncryptor.setConfig(config);
String encryptedText = "aHsFtlQjatrOP2s8bfLGkUG55z53KLNi";
String plainText = standardPBEStringEncryptor.decrypt(encryptedText);
System.out.println(plainText);
}