Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
880 views
in Technique[技术] by (71.8m points)

spring - org.jasypt.exceptions.EncryptionOperationNotPossibleException

I am using Jasypt-1.9.0 with Spring 3.1 and Hibernate 4.0.1. I have a requirement in my application to connect to database whose password(root) is stored in the encrypted form in the property file within the application.

I looked online and found the way with following links:

  1. http://www.jasypt.org/spring31.html

  2. http://www.jasypt.org/hibernate.html

  3. http://www.jasypt.org/encrypting-configuration.html

I have done the following steps and configuration for my requirement:

  • Added jasypt-1.9.0 and jasypt-hibernate4-1.9.0 in build path.
  • Added following in my dispatcher-servlet file:
< bean id="propertyConfigurer"
   class="org.jasypt.spring31.properties.EncryptablePropertyPlaceholderConfigurer">

  < constructor-arg ref="configurationEncryptor" />
  < property name="locations">
    < list>
      < value>classpath:database.properties< /value>
    < /list>
  < /property>
< /bean>

< bean id="configurationEncryptor"
    class="org.jasypt.encryption.pbe.StandardPBEStringEncryptor">
  < property name="config" ref="environmentVariablesConfiguration" />
< /bean>

< bean id="environmentVariablesConfiguration"
    class="org.jasypt.encryption.pbe.config.EnvironmentStringPBEConfig">
  < property name="algorithm" value="PBEWithMD5AndDES" />
  < property name="passwordEnvName" value="APP_ENCRYPTION_PASSWORD" />
</bean>
  • Using CLI tool of Jasypt 1.9.0, I have generated the password below(attached snapshot of CLI)

enter image description here - Added a new Environment Varibale as APP_ENCRYPTION_PASSWORD with value as root

  • Added the encrypted password in database.properties file
db.driverClassName=com.mysql.jdbc.Driver
db.url=jdbc:mysql://localhost:3306/db1
db.username=root
db.password=ENC(bmfeQmgP/hJrh+mj6NANKA==)

Now, if I run my application, the following exception appears:

org.jasypt.exceptions.EncryptionOperationNotPossibleException
    at org.jasypt.encryption.pbe.StandardPBEByteEncryptor.decrypt(StandardPBEByteEncryptor.java:981)
    at org.jasypt.encryption.pbe.StandardPBEStringEncryptor.decrypt(StandardPBEStringEncryptor.java:725)
    at org.jasypt.properties.PropertyValueEncryptionUtils.decrypt(PropertyValueEncryptionUtils.java:72)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The question is most probably out of date, but for future seekers... EncryptionOperationNotPossibleException is a general exception thrown by jasypt to mask other possible exceptions. This exception can occur when:

  • your jdk does not have the JCE unlimited strenght installed (most common case)
  • you had some data in the database that was encrypted before with other password
  • you had some data in database that were not encrypted before and you added encryption to some field
  • jasypt failed to decrypt the encrypted value from db because of some strange corruption of data
  • many many others, you just need to debug to find out the real cause..

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...