令我惊讶的是,下面的代码片段中的catch-block经常被绊倒。
Security.addProvider(new BouncyCastleProvider());
final Set<String> found = new HashSet<String>();
final Set<String> missing = new HashSet<String>();
final DefaultSignatureAlgorithmIdentifierFinder finder = new DefaultSignatureAlgorithmIdentifierFinder();
for (Service service : new BouncyCastleProvider().getServices()) {
if ("Signature".equals(service.getType())) {
final String algorithm = service.getAlgorithm();
try {
finder.find(algorithm);
found.add(algorithm);
} catch (IllegalArgumentException ex) {
missing.add(algorithm);
}
}
}
System.out.println("Found: " + found);
System.out.println("Missing: " + missing);
我似乎无法通过Finder使用大多数算法,即使存在提供这些算法的服务。我做错了什么?
- Update* 为了更好地说明这个问题,我对代码做了一些修改。可能有意思的是,我使用的是JDK1.5版本的BouncyCastle。上面的代码给出了以下输出:
找到:[RIPEMD 256使用RSA加密,MD5使用RSA加密,MD 2使用RSA加密,SHA 384使用RSA加密,SHA 224使用ECDSA,SHA 384使用DSA,SHA 256使用DSA,SHA 512使用RSA加密,SHA 512使用DSA,RIPEMD 160使用RSA加密,SHA 224使用RSA加密,SHA 256使用ECDSA,RIPEMD 128使用RSA加密,SHA 384使用ECDSA,SHA 256使用RSA加密,SHA 512使用ECDSA,SHA1使用RSA加密,SHA 224使用DSA]
遗失:[带有ECNR的SHA1、不带有ECDSA的SHA 512、带有ECDSA的RIPEMD 160、RSA、GOST 3410、带有ECNR的SHA 256、带有RSA/ISO 9796 -2的MD5、带有CVC-ECDSA的SHA1、带有RSA/PSS的SHA 384、带有RSA/PSS的SHA1、带有RSA加密的MD 4、带有RSASSA-PSS的SHA 512、带有ECNR的SHA 256、带有RSA/ISO 9796 -2的SHA1、带有RSA/PSS的SHA 224、带有CVC-ECDSA的SHA 224、带有RAWRSASSA-PSS的SHA 224、带有RSA/PSS的SHA 256、不带有DSA的SHA 384、带有ECNR的RIPEMD 160、带有RSA/ISO 9796 -2的RIPEMD 160、DSA、ECGOST 3410、带有ECNR的SHA 224、1.2.840.113549.1.1.10]
4条答案
按热度按时间0mkxixxg1#
我认为
DefaultSignatureAlgorithmIdentifierFinder
是bcmail API的一部分。它返回此API识别的算法标识符。(检查Cryptographic Message Syntax)另一方面,bouncy castle提供程序提供了更多的算法。您可以检查DefaultSignatureAlgorithmIdentifierFinder
的源代码,其中识别的算法是硬编码的:干杯!干杯!
yks3o0rb2#
您是否已将BouncyCastle添加到安全提供程序中?您可以使用以下代码行完成此操作:
tvokkenx3#
这个答案与BouncyCastle没有直接关系。但是,我认为这对其他人会很有用:
在我的例子中,我使用的是SpongyCastle。我遇到了类似的问题:org.e.h.p:无法创建签名者:提供商SC未在org.e.h.a.a.a上提供SHA 256 WITHRSA(源文件:101)
原来proguard删除了一些必需的类。在proguard配置文件中添加以下内容后:- 保持类org.spongycastle.**{ *;}
问题已解决。
fwzugrvs4#
您可以通过两个步骤将Bouncy Castle添加到您的java平台上的安全提供程序中:
1.将BC库(当前为bcpkix-jdk15on-149.jar、bcprov-jdk15on-149.jar)复制到目录$JAVA_HOME/jre/lib/ext/
2.注册BC提供商:编辑文件$JAVA_HOME/jre/lib/security/java.security和下面的行
添加您的BC提供商
更改其余提供程序的数量。整个提供程序块应类似于: