spring boot configuration file encryption, plaintext password encryption, properties and yml conversion

Keywords: Java Spring Spring Boot

1. Introduce maven

<dependency>
	<groupId>com.github.ulisesbocchio</groupId>
	<artifactId>jasypt-spring-boot-starter</artifactId>
	<version>3.0.3</version>
</dependency>
<dependency>
	<groupId>org.jasypt</groupId>
	<artifactId>jasypt</artifactId>
	<version>1.9.3</version>
</dependency>

2. Add configuration (yml format; properties and yml online conversion)

properties and yml online conversion: properties and yml online conversion

jasypt:
  encryptor:
    algorithm: PBEWithMD5AndDES		#Algorithm - Fixed writing method is generally not changed
    password: 1234qwer				#secret key
    iv-generator-classname: org.jasypt.iv.NoIvGenerator	#Sets the class name of the initial vector IV generator

3. Find the maven warehouse: org\jasypt\jasypt .9.3 and encrypt the content

  1. After opening to the place - enter cmd in the address bar - open the black window

  2. Enter after the window opens

    java -cp jasypt-1.9.3.jar org.jasypt.intf.cli.JasyptPBEStringEncryptionCLI input="root" password=1234qwer algorithm=PBEWithMD5AndDES
    

    The java -cp jasypt - version should be modified according to its own. jar org.jasypt.intf.cli.JasyptPBEStringEncryptionCLI input = "plaintext" password = key algorithm = algorithm. These three values should be the same as those in the configuration file

  3. Enter after input
    ----OUTPUT --------------------------- the following is the content after root plaintext encryption

  4. Copy the content (select the encrypted content with the mouse and right-click to copy) - replace the content in the configuration file - replace the password root in the configuration with the newly encrypted content and wrap it with ENC(); Enc () can be changed - if you don't want to use it, you can go to Baidu to change it

4. Common problems and troubleshooting methods

  1. Question 1
    Failed to bind properties under 'spring.datasource.password' to java.lang.String:      
    			Reason: org.jasypt.encryption.pbe.config.SimpleStringPBEConfig.setIvGeneratorClassName(Ljava/lang/String;)V
    
  2. Question 2
    Failed to bind properties under 'spring.datasource.password' to java.lang.String:
    			Reason: Failed to bind properties under 'spring.datasource.password' to java.lang.String
    		Action:
    			Update your application's configuration
    
  3. Question 3
    Description:
    		An attempt was made to call the method org.jasypt.encryption.pbe.config.SimpleStringPBEConfig.setIvGeneratorClassName(Ljava/lang/String;)V but it does not exist. Its class, org.jasypt.encryption.pbe.config.SimpleStringPBEConfig, is available from the following locations:
    			jar:file:/D:/yixing/maven/repository_uap/org/jasypt/jasypt/1.9.2/jasypt-1.9.2.jar!/org/jasypt/encryption/pbe/config/SimpleStringPBEConfig.class
    		It was loaded from the following location:
    			file:/D:/yixing/maven/repository_uap/org/jasypt/jasypt/1.9.2/jasypt-1.9.2.jar
    		Action:
    		Correct the classpath of your application so that it contains a single, compatible version of org.jasypt.encryption.pbe.config.SimpleStringPBEConfig
    
  4. Troubleshooting method
    1. First check whether there are problems in the configuration file and whether there are redundant spaces
    2. Is the version of jasypt-spring-boot-starter.jar too high
    3. No matter what version jasypt-spring-boot-starter.jar is, you can add IV generator classname: org.jasypt.iv.noivgenerator configuration - not only those above 3.0
    4. If all of the above are OK, that is the reason for the jar package conflict (problem 3 is the reason for the jar package conflict)
      View conflicting versions:

1. Click Show dependencies in maven to pop up the left view

2. Search for the jar package used for encryption in the view - in question 3, the jasypt.jar package conflict is reported, so search jasypt directly

3. You can see that two jasypts were found below; Click one of them to locate next to the jasypt package. You have to look for it to find the jasypt package. You can see that there is a conflict between 1.9.3 and 1.9.2 below (then we can look for 1.9.3 and 1.9.2. If you can find it, replace this version with the same one as the other)

Posted by metin on Sat, 02 Oct 2021 15:27:21 -0700