【问题标题】:Configure Jasypt Encryptors using my own SecretKey, instead of setting String password using the 'setPassword' method of the PBEString encryptors?使用我自己的 SecretKey 配置 Jasypt 加密器,而不是使用 PBEString 加密器的“setPassword”方法设置字符串密码?
【发布时间】:2014-08-21 03:56:32
【问题描述】:

我正在尝试使用以下代码配置 Jasypt StandardPBEStringEncryptor。

StandardPBEStringEncryptor strongEncryptor = new StandardPBEStringEncryptor();
strongEncryptor.setAlgorithm(ALGORITHM);
strongEncryptor.setPassword(PASSWORD);

然后调用'strongEncryptor'的encrypt()和decrypt()方法进行加解密操作。

是否有可能或者有一种方法可以使用 我自己的 SecretKey 而不是设置密码来配置 Jasypt 加密器?

就像在 Java Cipher 中一样,我们这样做...

Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
cipher.init(Cipher.ENCRYPT_MODE, MY_SECRET_KEY);

我看到 Jasypt 在内部使用字符串密码来创建 SecretKey 并启动 Java Cipher。可以在这里提供我的密钥吗?

【问题讨论】:

    标签: java encryption jasypt


    【解决方案1】:

    PBE 代表基于密码的加密

    这意味着不需要SecretKey,而是需要一个密码,然后通过多次散列来生成密钥。

    因此,为 PBE 加密手动设置 SecretKey 会使它的目的无效。正是出于这个原因,StandardPBEStringEncryptor 不允许这样做。 (更多信息请参见doc

    如果您想使用自己的SecretKey,只需使用标准加密函数即可。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-08
      • 2013-04-10
      • 1970-01-01
      • 2012-09-14
      • 2014-11-30
      • 1970-01-01
      相关资源
      最近更新 更多