首页 > 解决方案 > Jasypt 无法解密:org.jasypt.exceptions.EncryptionOperationNotPossibleException

问题描述

我已经使用下面注释掉的代码成功加密了一些值(它们只加密了一次,看起来像 ENC('asdhsjkdfhlakshlgkj'))。

    SimplePBEConfig config = new SimplePBEConfig(); 
        config.setKeyObtentionIterations(1000);
        config.setPassword("FilePassword");

        StandardPBEStringEncryptor encryptor = new org.jasypt.encryption.pbe.StandardPBEStringEncryptor();
        encryptor.setConfig(config);
        encryptor.initialize();
    
        Properties configFileProperties = readConfigFile();
//      for (Object key : configFileProperties.keySet()) {
//          if(key.toString().contains("password")) {
//              writeToConfigFile(key.toString(), PropertyValueEncryptionUtils.encrypt(configFileProperties.getProperty(key.toString()), encryptor));
//          }
//      }
        System.out.println(PropertyValueEncryptionUtils.decrypt("dev.password", encryptor));

我收到以下错误:

Exception in thread "main" org.jasypt.exceptions.EncryptionOperationNotPossibleException
    at org.jasypt.encryption.pbe.StandardPBEByteEncryptor.decrypt(StandardPBEByteEncryptor.java:918)
    at org.jasypt.encryption.pbe.StandardPBEStringEncryptor.decrypt(StandardPBEStringEncryptor.java:725)
    at org.jasypt.properties.PropertyValueEncryptionUtils.decrypt(PropertyValueEncryptionUtils.java:72)
    at Encrypt.main(Encrypt.java:28)

在这篇文章的第一个答案之后:https ://stackoverflow.com/questions/15544266/org-jasypt-exceptions-encryptionoperationnotpossibleexception#:~:text=EncryptionOperationNotPossibleException%20is%20a%20general%20exception,encrypted%20before%20with%20other %20密码

我已按照以下说明将正确的策略文件添加到我的 JRE(JAR 方法,因为我是没有 YUM 的 Windows 机器):https ://docs.datastax.com/en/cassandra-oss/3.0/cassandra/configuration/安装JCE.html

然后我重新启动我的电脑只是为了确保。仍然得到同样的错误。

标签: javaencryptionjasypt

解决方案


推荐阅读