话不多说导入jar包
<dependency>
<groupId>com.melloware</groupId>
<artifactId>jasypt</artifactId>
<version>1.9.4</version>
</dependency>
input 为需要加密的明文密码;
password 为私钥;
algorithm 为固定规则。
ENC加密
String[] createStr = new String[]{"input=abc123", "password=test", "algorithm=PBEWithMD5AndDES"};
JasyptPBEStringEncryptionCLI.main(createStr);
执行结果如下
----ENVIRONMENT-----------------
Runtime: Amazon.com Inc. OpenJDK 64-Bit Server VM 25.322-b06
----ARGUMENTS-------------------
algorithm: PBEWithMD5AndDES
input: abc123
password: test
----OUTPUT----------------------
im7D+efvNyE/nWAmYOEJaUMMP1GrLO1BLye+CUtyo4E=
ENC解密
String[] parseStr = new String[]{"input=npFKUnWpBY3rvAWt7spetH8waN0nrRVCbxO853pQ7Os=", "password=test", "algorithm=PBEWithMD5AndDES"};
JasyptPBEStringDecryptionCLI.main(parseStr);
执行结果
----ENVIRONMENT-----------------
Runtime: Amazon.com Inc. OpenJDK 64-Bit Server VM 25.322-b06
----ARGUMENTS-------------------
algorithm: PBEWithMD5AndDES
input: npFKUnWpBY3rvAWt7spetH8waN0nrRVCbxO853pQ7Os=
password: test
----OUTPUT----------------------
abc123