加解密
1.pom依赖
代码语言:javascript
复制<dependency>
<groupId>org.jasypt</groupId>
<artifactId>jasypt-spring31</artifactId>
<version>1.9.2</version>
</dependency>
2.代码
代码语言:javascript
复制import java.lang.reflect.InvocationTargetException;
import org.jasypt.util.text.BasicTextEncryptor;
import org.junit.Test;
public class JasyptTest{
@Test
public void jasyptTest(){
BasicTextEncryptor encryptor = new BasicTextEncryptor();
try{
String privateKey1 = "key1";
String privateKey2 = "key2";
BasicTextEncryptor.class.getMethod(str1 str2,String.class)
.invoke(encryptor, "key3");
}catch(Exception e){
System.out.println("init fail...");
}
String result = encryptor.encrypt("password");
System.out.println("加密结果:" result);
String pass = encryptor.decrypt(result);
System.out.println("解密结果:" pass);
}
}