加密:
java -cp C:UsersAdministrator.m2repositoryorgjasyptjasypt1.9.2jasypt-1.9.2.jar org.jasypt.intf.cli.JasyptPBEStringEncryptionCLI input="原密码" password=盐 algorithm=PBEWithMD5AndDES
java -cp C:UsersAdministrator.m2repositoryorgjasyptjasypt1.9.3jasypt-1.9.3.jar org.jasypt.intf.cli.JasyptPBEStringEncryptionCLI input="原密码" password=盐 algorithm=PBEWITHHMACSHA512ANDAES_256 ivGeneratorClassName=org.jasypt.iv.RandomIvGenerator
解密:
java -cp C:UsersAdministrator.m2repositoryorgjasyptjasypt1.9.2jasypt-1.9.2.jar org.jasypt.intf.cli.JasyptPBEStringDecryptionCLI input="加密后的密码" password=盐 algorithm=PBEWithMD5AndDES
java -cp C:UsersAdministrator.m2repositoryorgjasyptjasypt1.9.3jasypt-1.9.3.jar org.jasypt.intf.cli.JasyptPBEStringDecryptionCLI input="加密后的密码" password=盐 algorithm=PBEWITHHMACSHA512ANDAES_256 ivGeneratorClassName=org.jasypt.iv.RandomIvGenerator
input:是数据库的明文密码
password:是机密的盐
algorithm:是加密的方式(默认)
Maven依赖
<dependency> <groupId>com.github.ulisesbocchio</groupId> <artifactId>jasypt-spring-boot-starter</artifactId> <version>1.16</version> </dependency>
3 调用JAVA API 生成密文
public static void main(String[] args) { BasicTextEncryptor textEncryptor = new BasicTextEncryptor(); //加密所需的salt(盐) textEncryptor.setPassword("G0CvDz7oJn6"); //要加密的数据(数据库的用户名或密码) String username = textEncryptor.encrypt("root"); String password = textEncryptor.encrypt("root123"); System.out.println("username:"+username); System.out.println("password:"+password);}4. jasypt-1.9.3.jar 加密一直报错Operation not possible (Bad input or parameters)
改两个参数就解决了 algorithm=PBEWITHHMACSHA512ANDAES_256 ivGeneratorClassName=org.jasypt.iv.RandomIvGenerator