PBEWITHSHA256AND128BITAES-CBC-BC在RedHat上创建java.security.NoSuchAlgorithmException 6.4 [英] PBEWITHSHA256AND128BITAES-CBC-BC creating java.security.NoSuchAlgorithmException on RedHat 6.4
问题描述
我们有一个使用 Bouncy Castle
使用 PBEWITHSHA256AND128BITAES-CBC-BC
算法加密数据的应用程序。它在 Unbuntu
运行 OpenJDK 1.7
下运行正常。但是当我们将它移动到 RedHat 6.4
时也会运行 OpenJDK 1.7
,我们得到以下异常:
java.security.NoSuchAlgorithmException
$ b b
对可能导致这种情况的任何想法。如何将 PBEWITHSHA256AND128BITAES-CBC-BC
算法添加到 RedHat 6.4
?
ps ,应用程式正在 JBoss
中执行。
private String cryptoAlgorithm =PBEWITHSHA256AND128BITAES-CBC-BC;
Security.addProvider(new BouncyCastleProvider());
//从配置的外部文件加载passPhrase到char数组。
char [] passPhrase = null;
try {
passPhrase = loadPassPhrase(passPhraseFile);
} catch(FileNotFoundException e){
throw BeanHelper.logException(LOG,methodName,new EJBException(找不到文件:+ 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(Key spec is invalid,e));
}
(在RH 6.4 )
#java -version
java版本1.7.0_19
OpenJDK运行环境(rhel-2.3.9.1.el6_4 -x86_64)
OpenJDK 64位服务器虚拟机(构建23.7-b01,混合模式)
在Ubuntu 12.04上)
#java版本1.7.0_15
OpenJDK运行时环境(IcedTea7 2.3.7)(7u15-2.3.7-0ubuntu1〜12.04)
OpenJDK 64位服务器虚拟机(构建23.7-b01,混合模式)
你的类路径中有BouncyCastle提供者JAR(例如bcprov-jdk15on-149.jar) p>
我用最小的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
We have an application that uses Bouncy Castle
to encrypt data using PBEWITHSHA256AND128BITAES-CBC-BC
algorithm. It works fine on Unbuntu
running OpenJDK 1.7
. But when when we move it to RedHat 6.4
also running OpenJDK 1.7
, we get the following exception:
java.security.NoSuchAlgorithmException
Any thoughts on what could be causing this. How can we add PBEWITHSHA256AND128BITAES-CBC-BC
algorithm to RedHat 6.4
?
p.s. the application is running in 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));
}
(On 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)
(On 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)
Do you have the BouncyCastle provider JAR (e.g. bcprov-jdk15on-149.jar) in your classpath?
I tested your scenario with a minimal CentOS 6.4 (64-bit) installation, OpenJDK 1.7 and BouncyCastle 1.49, and found no issues with it.
I placed the JAR in the JRE lib/ext directory:
/usr/lib/jvm/java-1.7.0-openjdk.x86_64/jre/lib/ext
这篇关于PBEWITHSHA256AND128BITAES-CBC-BC在RedHat上创建java.security.NoSuchAlgorithmException 6.4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!