pbewithhmacsha512和256bitaes抛出org.jasypt.exceptions.encryptioninitializationexception(jasypt)

ccrfmcuu  于 2021-07-03  发布在  Java
关注(0)|答案(0)|浏览(393)

我正在尝试使用jasypt加密和解密密码。我将代码编写为:

// Constructor
public Encrypt() {

    super();

    pooledPBEStringEncryptor = new PooledPBEStringEncryptor();

    pooledPBEStringEncryptor.setPassword(encryptionKey);
    pooledPBEStringEncryptor.setAlgorithm("PBEWITHHMACSHA512AND256BITAES");
    pooledPBEStringEncryptor.setPoolSize(4);
    pooledPBEStringEncryptor.setSaltGenerator(new RandomSaltGenerator());
}
``` `encryptionKey` 是静态字符串。要加密的代码是:

public static String encryptIt(String value) {

String encrypted = null;

// Encrypt & Encode
try {

    encrypted = pooledPBEStringEncryptor.encrypt(value);            

} catch (Exception e) {
    throw new RuntimeException("Security Error in doEncrypt: " + e);
}

return encrypted;

}

现在当我运行代码时。我得到一个错误:

org.jasypt.exceptions.EncryptionInitializationException: java.lang.ExceptionInInitializerError
at org.jasypt.encryption.pbe.StandardPBEByteEncryptor.initialize(StandardPBEByteEncryptor.java:773)
at org.jasypt.encryption.pbe.StandardPBEByteEncryptor.cloneAndInitializeEncryptor(StandardPBEByteEncryptor.java:535)
at org.jasypt.encryption.pbe.StandardPBEStringEncryptor.cloneAndInitializeEncryptor(StandardPBEStringEncryptor.java:483)
at org.jasypt.encryption.pbe.PooledPBEStringEncryptor.initialize(PooledPBEStringEncryptor.java:405)
at org.jasypt.encryption.pbe.PooledPBEStringEncryptor.encrypt(PooledPBEStringEncryptor.java:456)
at com.gtt.common.Encrypt.doEncrypt(Encrypt.java:96)
at com.gtt.common.Encrypt.main(Encrypt.java:278)
Caused by: java.lang.ExceptionInInitializerError
at java.lang.J9VMInternals.ensureError(J9VMInternals.java:147)
at java.lang.J9VMInternals.recordInitializationFailure(J9VMInternals.java:136)
at javax.crypto.SecretKeyFactory.a(Unknown Source)
at javax.crypto.SecretKeyFactory.(Unknown Source)
at javax.crypto.SecretKeyFactory.getInstance(Unknown Source)
at org.jasypt.encryption.pbe.StandardPBEByteEncryptor.initialize(StandardPBEByteEncryptor.java:761)
... 6 more
Caused by: java.lang.SecurityException: Cannot set up certs for trusted CAs
at javax.crypto.b.(Unknown Source)
... 10 more
Caused by: java.lang.SecurityException: Jurisdiction policy files are not signed by trusted signers!
at javax.crypto.b.a(Unknown Source)
at javax.crypto.b.c(Unknown Source)
at javax.crypto.b.access$600(Unknown Source)
at javax.crypto.b$a.run(Unknown Source)
at java.security.AccessController.doPrivileged(AccessController.java:734)
... 11 more
Exception in thread "main" java.lang.RuntimeException: Security Error in doEncrypt: org.jasypt.exceptions.EncryptionInitializationException: java.lang.ExceptionInInitializerError
at com.gtt.common.Encrypt.doEncrypt(Encrypt.java:101)
at com.gtt.common.Encrypt.main(Encrypt.java:278)

一开始我得到的是 `EncryptionNotPossible` 例外。但我在google上搜索了一下,发现我需要把jcejars(本地和美国策略)放到jre的安全文件夹中。在这样做之后,我得到了这个错误。你能告诉我我做错了什么吗?如果jdk1.8有用的话,我正在使用它。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题