PBEWITHSHA256AND128BITAES

PBEWITHSHA256AND128BITAES

我们有一个使用Bouncy Castle来使用PBEWITHSHA256AND128BITAES-CBC-BC算法加密数据的应用程序。它在运行UbuntuOpenJDK 1.7上运行良好。但是,当我们将其移动到还运行RedHat 6.4OpenJDK 1.7时,会出现以下异常:



关于可能导致此问题的任何想法。我们如何在PBEWITHSHA256AND128BITAES-CBC-BC中添加RedHat 6.4算法?

p.s. 该应用程序正在JBoss中运行。

private String cryptoAlgorithm = "PBEWITHSHA256AND128BITAES-CBC-BC";

Security.addProvider(new BouncyCastleProvider());

// load passPhrase from configured external file to char array.
char[] passPhrase = null;
try {
    passPhrase = loadPassPhrase(passPhraseFile);
} catch (FileNotFoundException e) {
    throw BeanHelper.logException(LOG, methodName, new EJBException("The file not found: " + passPhraseFile, e));
} catch (IOException e) {
    throw BeanHelper.logException(LOG, methodName, new EJBException("Error in reading file: " + passPhraseFile, e));
}

PBEKeySpec pbeKeySpec = new PBEKeySpec(passPhrase);

try {
    SecretKeyFactory secretKeyFactory = SecretKeyFactory.getInstance(cryptoAlgorithm);
    SecretKey newSecretKey = secretKeyFactory.generateSecret(pbeKeySpec);
    return newSecretKey;
} catch (NoSuchAlgorithmException e) {
    throw BeanHelper.logException(LOG, methodName, new EJBException("The algorithm is not found: " + cryptoAlgorithm, e));
} catch (InvalidKeySpecException e) {
    throw BeanHelper.logException(LOG, methodName, new EJBException("The key spec is invalid", e));
}

(在RH 6.4上为)
#java -version
java version "1.7.0_19"
OpenJDK Runtime Environment (rhel-2.3.9.1.el6_4-x86_64)
OpenJDK 64-Bit Server VM (build 23.7-b01, mixed mode)

(在Ubuntu 12.04上为 )
#java version "1.7.0_15"
OpenJDK Runtime Environment (IcedTea7 2.3.7) (7u15-2.3.7-0ubuntu1~12.04)
OpenJDK 64-Bit Server VM (build 23.7-b01, mixed mode)

最佳答案

您的类路径中是否有BouncyCaSTLe提供程序JAR(例如bcprov-jdk15on-149.jar)?

我使用最小的CentOS 6.4(64位)安装,OpenJDK 1.7和BouncyCaSTLe 1.49测试了您的方案,但发现没有问题。

我将JAR放在JRE lib/ext目录中:

/usr/lib/jvm/java-1.7.0-openjdk.x86_64/jre/lib/ext

10-08 01:34