jasypt-spring-boot use

  1. Maven dependencies
    <dependency>
      <groupId>com.github.ulisesbocchio</groupId>
      <artifactId>jasypt-spring-boot-starter</artifactId>
      <version>1.14</version>
    </dependency>


  2. encrypted password

    The encryption command is as follows (the red part represents the password that needs to be encrypted):

    java -cp F://.m2/repository/org/jasypt/jasypt/1.9.2/jasypt-1.9.2.jar org.jasypt.intf.cli.JasyptPBEStringEncryptionCLI input="test123" password=e9fbdb2d3b21 algorithm=PBEWithMD5AndDES


    The command echo is as follows (the red part is the encrypted ciphertext):

    copy code
    ----ENVIRONMENT-----------------
    Runtime: Oracle Corporation Java HotSpot(TM) 64-Bit Server VM 25.121-b13
    ----ARGUMENTS-------------------
    algorithm: PBEWithMD5AndDES
    input: test123
    password: e9fbdb2d3b21
    ----OUTPUT----------------------
    ArGx5ir2xs+CmXRhMnThpQ==
    copy code

     

  3. 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(ArGx5ir2xs+CmXRhMnThpQ==)

    The spring.datasource.password obtained in the program will be automatically converted into plaintext content (test123).

  4. Configure ciphertext password

    Configure the JVM parameter (jasypt.encryptor.password) in the startup command and inject the password of the encrypted ciphertext.
    Such as:

    java -Dfile.encoding=UTF8 -Djasypt.encryptor.password=e9fbdb2d3b21 -jar -Xmx512m settlement.jar

    Note: The password of the ciphertext in the docker container can be set as an environment variable (eg: JASYPT_PASSWORD ), the above command can be modified as:

    java -Dfile.encoding=UTF8 -Djasypt.encryptor.password=${JASYPT_PASSWORD} -jar -Xmx512m settlement.jar

     

  5. Reference documentation
    https://www.ricston.com/blog/encrypting-properties-in-spring-boot-with-jasypt-spring-boot/
    https://github.com/ulisesbocchio/jasypt-spring-boot

Reprinted from: https://www.cnblogs.com/zz0412/p/jasypt-001.html

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326487228&siteId=291194637