org.jasypt.exceptions.EncryptionOperationNotPossibleException

Aru*_*mar 10 spring hibernate password-encryption jasypt

我使用Jasypt-1.9.0弹簧3.1Hibernate的4.0.1.我的应用程序中要求连接到数据库,其密码(root)以加密形式存储在应用程序的属性文件中.

我在网上查找了以下链接:

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

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

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

我已根据我的要求完成了以下步骤和配置:

  • 在构建路径中添加了jasypt-1.9.0jasypt-hibernate4 -1.9.0.
  • 在我的dispatcher-servlet文件中添加了以下内容:

<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>
Run Code Online (Sandbox Code Playgroud)
  • 使用Jasypt 1.9.0的CLI工具,我在下面生成了密码(CLI的附件快照)

在此输入图像描述 - 添加了一个新的Environment Varibale作为APP_ENCRYPTION_PASSWORD,其值为root

  • database.properties文件中添加了加密密码
db.driverClassName=com.mysql.jdbc.Driver
db.url=jdbc:mysql://localhost:3306/db1
db.username=root
db.password=ENC(bmfeQmgP/hJrh+mj6NANKA==)
Run Code Online (Sandbox Code Playgroud)

现在如果我运行我的应用程序,则出现以下异常:

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)
Run Code Online (Sandbox Code Playgroud)

Nad*_*dir 11

问题很可能是过时的,但是对于未来的搜索者来说...... EncryptionOperationNotPossibleException是jasypt抛出的一般异常,用于掩盖其他可能的异常.以下情况可能发生此异常:

  • 你的jdk没有安装JCE无限强度(最常见的情况)
  • 你有一些数据在数据库中使用其他密码加密
  • 您在数据库中有一些以前未加密的数据,并且您在某些字段中添加了加密
  • 由于数据的一些奇怪的破坏,jasypt无法解密db中的加密值
  • 许多其他人,你只需要调试,找出真正的原因..


小智 5

如果您在加密过程中没有指定所有参数,Jasypt 将使用默认值。确保在解密期间使用这些确切的默认值。不然你可能会遇到麻烦...

这对我来说工作:

mvn jasypt:encrypt -Djasypt.encryptor.password='secret' \
    -Djasypt.encryptor.algorithm=PBEWITHHMACSHA512ANDAES_256 \
    -Djasypt.encryptor.iv-generator-classname=org.jasypt.iv.RandomIvGenerator \
    -Djasypt.encryptor.salt-generator-classname=org.jasypt.salt.RandomSaltGenerator \
    -Djasypt.encryptor.key-obtention-iterations=1000  \
    -Djasypt.plugin.path='file:application.yml' 
Run Code Online (Sandbox Code Playgroud)
mvn jasypt:decrypt -Djasypt.encryptor.password='secret' \
    -Djasypt.encryptor.algorithm=PBEWITHHMACSHA512ANDAES_256 \
    -Djasypt.encryptor.iv-generator-classname=org.jasypt.iv.RandomIvGenerator \
    -Djasypt.encryptor.salt-generator-classname=org.jasypt.salt.RandomSaltGenerator \
    -Djasypt.encryptor.key-obtention-iterations=1000  \
    -Djasypt.plugin.path='file:application.yml' 
Run Code Online (Sandbox Code Playgroud)