ulisesbocchio / jasypt-spring-boot

Jasypt integration for Spring boot
MIT License
2.91k stars 522 forks source link

Decryption of Properties failed, make sure encryption/decryption passwords match #101

Closed springnotes00 closed 5 years ago

springnotes00 commented 6 years ago

Hello

I have jasypt-spring-boot-1.17 with spring version "4.2.5.RELEASE" and spring Boot version "1.5.3.RELEASE".

I am using the first method from this website (https://github.com/ulisesbocchio/jasypt-spring-boot) since I use @SpringBootApplication in my application.java class.

I did the first testing.

  1. I used this notation @PropertySource("classpath:sampleservices.yml") or @PropertySource("classpath:sampleservices.properties") in my ApplicationMain.java.
  2. I saved the ENC() password in a separate file, either the sampleservices.yml or the sampleservices.properties.
  3. I defined the following code in my application.yml file. I set the plain password value for JASYPT_ENCRYPTOR_PASSWORD in the environmental variable. The test was successful. jasypt: encryptor: bean: encryptorBean password: ${JASYPT_ENCRYPTOR_PASSWORD:}

However, the real encrypted ENC() password is stored in the following nested fashion in my application.yml file. Please let me know what exactly I should implement in order to have the decryption process happen successful. I need to use this decrypted password to login to DB.

I did change this code @PropertySource("application.yml") but I don't know how to get to the password field here.

From application.yml file: Spring: profiles: sample datasource: driver-class-name: com.mysql.jdbc.Driver url: jdbc:mysql:abc username: userid password: ENC(xxxxxxxx)

I kept getting this error.

com.ulisesbocchio.jasyptspringboot.exception.DecryptionException: Decryption of Properties failed,  make sure encryption/decryption passwords match
at com.ulisesbocchio.jasyptspringboot.resolver.DefaultPropertyResolver.resolvePropertyValue(DefaultPropertyResolver.java:37) ~[jasypt-spring-boot-1.17.jar!/:?]

Thanks a lot!
ulisesbocchio commented 5 years ago

check out newly added DB password sample: https://github.com/ulisesbocchio/jasypt-spring-boot-samples/tree/master/jasypt-spring-boot-demo-db-h2

My guess is that you're encrypting the property with a different password/config to the password/config you're running the app with

poomcyber commented 5 years ago

I have had the same problem on spring boot 2.1.3. But I found out later it was just my silly case. I just understand it wrong between "input" and "password" parameter meaning. When I encrypt on Command prompt I thought "input" means key then I swap value between two of them when I run the application.

So, remember:

input=[your real password]

password=[is the jasypt key]

If this is not your root cause, another thing to consider is when you encrypt password on Windows it may not be able to use on Linux. You may have to encrypt on Linux when need to run applications on Linux.

rsingh33 commented 4 years ago

Hi I know this is an old thread but I am stuck on this issue for days now, when I run this app on my local it works fine, but when I run the same on build server(Bamboo Server) I get below exception. It gives both the messages password mismatch as well as unlimited strength JCE missing. Can someone please advise, it's really urgent

Caused by: com.ulisesbocchio.jasyptspringboot.exception.DecryptionException: Decryption of Properties failed, make sure encryption/decryption passwords match build 05-Aug-2020 16:14:41 Caused by: org.jasypt.exceptions.EncryptionOperationNotPossibleException: Encryption raised an exception. A possible cause is you are using strong encryption algorithms and you have not installed the Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files in this Java Virtual Machine

aniketrb-github commented 2 years ago

Hi I know this is an old thread but I am stuck on this issue for days now, when I run this app on my local it works fine, but when I run the same on build server(Bamboo Server) I get below exception. It gives both the messages password mismatch as well as unlimited strength JCE missing. Can someone please advise, it's really urgent

Caused by: com.ulisesbocchio.jasyptspringboot.exception.DecryptionException: Decryption of Properties failed, make sure encryption/decryption passwords match build 05-Aug-2020 16:14:41 Caused by: org.jasypt.exceptions.EncryptionOperationNotPossibleException: Encryption raised an exception. A possible cause is you are using strong encryption algorithms and you have not installed the Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files in this Java Virtual Machine

You can checkout my answer here and tryout. Hope it helps.

aniketrb-github commented 2 years ago

I have had the same problem on spring boot 2.1.3. But I found out later it was just my silly case. I just understand it wrong between "input" and "password" parameter meaning. When I encrypt on Command prompt I thought "input" means key then I swap value between two of them when I run the application.

So, remember:

input=[your real password] password=[is the jasypt key]

If this is not your root cause, another thing to consider is when you encrypt password on Windows it may not be able to use on Linux. You may have to encrypt on Linux when need to run applications on Linux.

I consolidated my workarounds and have added them here which helped me resolve the exception. True, input and password and 2 confusing terms used, they could have been much better. You have added a good insight which is a common mistake most of the times.

jlmanohar commented 1 year ago

I am using 1.18 version of this plugin and can't update as i use older spring boot. How do I encrypt on windows and deploy in Linux ?

I use spring tools to develop and test in windows, then deploy to jboss on rhel. I get decryption failed, make sure password is same .. something like that.

And yes when i try with encrypted props from rhel, it works fine..