jasypt-spring-boot instructions for use
encrypted password
Order:
java -cp F://.m2/repository/org/jasypt/jasypt/1.9.2/jasypt-1.9.2.jar org.jasypt.intf.cli.JasyptPBEStringEncryptionCLI
input="test123" password=e9fbdb2d3b213c28575c095ae0029e05f40f77ee53ecd24af815bdff5479dd2a
algorithm=PBEWithMD5AndDES
The red part represents the password that needs to be encrypted. The command echo is as follows (the red part is the encrypted ciphertext):
----ENVIRONMENT-----------------
Runtime: Oracle Corporation Java HotSpot(TM) 64-Bit Server VM 25.121-b13
----ARGUMENTS-------------------
algorithm: PBEWithMD5AndDES
input: test123
password: e9fbdb2d3b213c28575c095ae0029e05f40f77ee53ecd24af815bdff5479dd2a
----OUTPUT----------------------
ZV / jFn9unPE2xHIGJLl7WQ ==
Maven dependencies
<dependency>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-spring-boot-starter</artifactId>
<version>1.14</version>
</dependency>
Set the ciphertext in the program
To set the ciphertext in the program, you need to use the following format:
ENC (ciphertext)
Such as:
spring.datasource.password=ENC(ZV/jFn9unPE2xHIGJLl7WQ==)
The spring.datasource.password obtained in the program will be automatically converted into plaintext content (test123).
Configure ciphertext password
Configure the JVM parameter ( jasypt.encryptor.password ) in the startup command to inject the password of the encrypted ciphertext.
Such as:
java -Dfile.encoding=UTF8 -
Djasypt.encryptor.password= e9fbdb2d3b213c28575c095ae0029e05f40f77ee53ecd24af815bdff5479dd2a -jar -
Xmx512m gh_settlement.jar
Note: The password of the ciphertext in the docker container will be set to the environment variable JASYPT_PASSWORD, so the above command needs to be modified to:
java -Dfile.encoding=UTF8 -Djasypt.encryptor.password= ${JASYPT_PASSWORD } -jar -Xmx512m
gh_settlement.jar
Reference documentation
https://www.ricston.com/blog/encrypting-properties-in-spring-boot-with-jasypt-spring-boot/
https://github.com/ulisesbocchio/jasypt-spring-boot
package com; import org.jasypt.intf.service.JasyptStatelessService; public final class JasyptPBEStringEncryption { /** * <p> * CLI execution method. * </p> * * @param args the command execution arguments */ public static void main(final String[] args) { try { final JasyptStatelessService service = new JasyptStatelessService(); // Content that needs to be encrypted final String input = "guohuaiGUO4056&";// final String password = "e9fbdb2d3b213c28575c095ae0029e05f40f77ee53ecd24af815bdff5479dd2a"; // final String algorithm = "PBEWithMD5AndDES"; // final String result = service.encrypt(input, password, null, null, algorithm, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null); System.out.println("input=" + input); System.out.println("result=" + result); } catch (Throwable t) { t.printStackTrace(); } } }