BouncyCastle не находит алгоритмы, которые предоставляет?

Я играю с BouncyCastle 1.46 К моему удивлению, блокировщик в приведенном ниже фрагменте срабатывает довольно часто. .

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, хотя существуют службы, которые предоставляют эти алгоритмы. Что я делаю неправильно?

Обновление Я немного изменил код, чтобы лучше проиллюстрировать проблему. Что может быть интересно, так это то, что я использую версию BouncyCastle для JDK1.5. Приведенный выше код дает следующий результат:

Найдено: [RIPEMD256WithRSAEncryption, MD5WithRSAEncryption, MD2WithRSAEncryption, SHA384WithRSAEncryption, SHA224WITHECDSA, SHA384WITHDSA, SHA256WITHDSA, SHA512WithRSAEncryption, SHA512WITHDSA, RIPEMD160WithRSAEncryption, SHA224WithRSAEncryption, SHA256WITHECDSA, RIPEMD128WithRSAEncryption, SHA384WITHECDSA, SHA256WithRSAEncryption, SHA512WITHECDSA, SHA1WithRSAEncryption, SHA224WITHDSA]

Отсутствующие: [SHA1WITHECNR, NONEwithECDSA, ECDSA, SHA512withRSA / PSS, RIPEMD160WITHECDSA, RSA, GOST3410, SHA256WITHECNR, MD5withRSA / ISO9796-2, SHA1WITHCVC-ECDSA, SHA384withRSA / PSS, SHA1withRSA / PSS, MD4WithRSAEncryption, RSASSA-PSS, SHA512WITHECNR, SHA256WITHCVC-ECDSA , SHA1 с RSA / ISO9796-2, SHA224 с RSA / PSS, SHA224WITHCVC-ECDSA, RAWRSASSA-PSS, SHA256 с RSA / PSS, NONEWITHDSA, SHA384WITHECNR, RIPEMD160 с RSA / ISO9796-249, DSA / ISO976-224, DSA / ISO1201-224, 1.2.810.140.140.124, ECM.


person Guus    schedule 08.01.2012    source источник
comment
Можете ли вы отладить его и добавить к своему вопросу, что возвращается в service.getAlgorithm()?   -  person Óscar López    schedule 08.01.2012


Ответы (4)


Я думаю, что DefaultSignatureAlgorithmIdentifierFinder является частью bcmail API. Он возвращает идентификаторы алгоритмов, распознаваемые этим API. (Проверьте Синтаксис криптографических сообщений) С другой стороны, провайдер надувных каст предоставляет больше алгоритмов. Вы можете проверить источник DefaultSignatureAlgorithmIdentifierFinder, в котором жестко запрограммированы распознанные алгоритмы:

algorithms.put("MD2WITHRSAENCRYPTION", PKCSObjectIdentifiers.md2WithRSAEncryption);
algorithms.put("MD2WITHRSA", PKCSObjectIdentifiers.md2WithRSAEncryption);
algorithms.put("MD5WITHRSAENCRYPTION", PKCSObjectIdentifiers.md5WithRSAEncryption);
algorithms.put("MD5WITHRSA", PKCSObjectIdentifiers.md5WithRSAEncryption);
algorithms.put("SHA1WITHRSAENCRYPTION", PKCSObjectIdentifiers.sha1WithRSAEncryption);
algorithms.put("SHA1WITHRSA", PKCSObjectIdentifiers.sha1WithRSAEncryption);
algorithms.put("SHA224WITHRSAENCRYPTION", PKCSObjectIdentifiers.sha224WithRSAEncryption);
algorithms.put("SHA224WITHRSA", PKCSObjectIdentifiers.sha224WithRSAEncryption);
algorithms.put("SHA256WITHRSAENCRYPTION", PKCSObjectIdentifiers.sha256WithRSAEncryption);
algorithms.put("SHA256WITHRSA", PKCSObjectIdentifiers.sha256WithRSAEncryption);
algorithms.put("SHA384WITHRSAENCRYPTION", PKCSObjectIdentifiers.sha384WithRSAEncryption);
algorithms.put("SHA384WITHRSA", PKCSObjectIdentifiers.sha384WithRSAEncryption);
algorithms.put("SHA512WITHRSAENCRYPTION", PKCSObjectIdentifiers.sha512WithRSAEncryption);
algorithms.put("SHA512WITHRSA", PKCSObjectIdentifiers.sha512WithRSAEncryption);
algorithms.put("SHA1WITHRSAANDMGF1", PKCSObjectIdentifiers.id_RSASSA_PSS);
algorithms.put("SHA224WITHRSAANDMGF1", PKCSObjectIdentifiers.id_RSASSA_PSS);
algorithms.put("SHA256WITHRSAANDMGF1", PKCSObjectIdentifiers.id_RSASSA_PSS);
algorithms.put("SHA384WITHRSAANDMGF1", PKCSObjectIdentifiers.id_RSASSA_PSS);
algorithms.put("SHA512WITHRSAANDMGF1", PKCSObjectIdentifiers.id_RSASSA_PSS);
algorithms.put("RIPEMD160WITHRSAENCRYPTION", TeleTrusTObjectIdentifiers.rsaSignatureWithripemd160);
algorithms.put("RIPEMD160WITHRSA", TeleTrusTObjectIdentifiers.rsaSignatureWithripemd160);
algorithms.put("RIPEMD128WITHRSAENCRYPTION", TeleTrusTObjectIdentifiers.rsaSignatureWithripemd128);
algorithms.put("RIPEMD128WITHRSA", TeleTrusTObjectIdentifiers.rsaSignatureWithripemd128);
algorithms.put("RIPEMD256WITHRSAENCRYPTION", TeleTrusTObjectIdentifiers.rsaSignatureWithripemd256);
algorithms.put("RIPEMD256WITHRSA", TeleTrusTObjectIdentifiers.rsaSignatureWithripemd256);
algorithms.put("SHA1WITHDSA", X9ObjectIdentifiers.id_dsa_with_sha1);
algorithms.put("DSAWITHSHA1", X9ObjectIdentifiers.id_dsa_with_sha1);
algorithms.put("SHA224WITHDSA", NISTObjectIdentifiers.dsa_with_sha224);
algorithms.put("SHA256WITHDSA", NISTObjectIdentifiers.dsa_with_sha256);
algorithms.put("SHA384WITHDSA", NISTObjectIdentifiers.dsa_with_sha384);
algorithms.put("SHA512WITHDSA", NISTObjectIdentifiers.dsa_with_sha512);
algorithms.put("SHA1WITHECDSA", X9ObjectIdentifiers.ecdsa_with_SHA1);
algorithms.put("ECDSAWITHSHA1", X9ObjectIdentifiers.ecdsa_with_SHA1);
algorithms.put("SHA224WITHECDSA", X9ObjectIdentifiers.ecdsa_with_SHA224);
algorithms.put("SHA256WITHECDSA", X9ObjectIdentifiers.ecdsa_with_SHA256);
algorithms.put("SHA384WITHECDSA", X9ObjectIdentifiers.ecdsa_with_SHA384);
algorithms.put("SHA512WITHECDSA", X9ObjectIdentifiers.ecdsa_with_SHA512);
algorithms.put("GOST3411WITHGOST3410", CryptoProObjectIdentifiers.gostR3411_94_with_gostR3410_94);
algorithms.put("GOST3411WITHGOST3410-94", CryptoProObjectIdentifiers.gostR3411_94_with_gostR3410_94);
algorithms.put("GOST3411WITHECGOST3410", CryptoProObjectIdentifiers.gostR3411_94_with_gostR3410_2001);
algorithms.put("GOST3411WITHECGOST3410-2001", CryptoProObjectIdentifiers.gostR3411_94_with_gostR3410_2001);
algorithms.put("GOST3411WITHGOST3410-2001", CryptoProObjectIdentifiers.gostR3411_94_with_gostR3410_2001);

Ваше здоровье!

person Lachezar Balev    schedule 08.01.2012

Этот ответ не имеет прямого отношения к BouncyCastle. Но я подумал, что это будет полезно для других:

В моем случае я использовал SpongyCastle. У меня аналогичная проблема: org.e.h.p: невозможно создать подписывающего: Provider SC не предоставляет SHA256WITHRSA в org.e.h.a.a.a (SourceFile: 101)

Оказалось, что proguard удалял некоторые из требуемых классов. После добавления в конфигурационный файл proguard следующего: -keep class org.spongycastle. ** {*; }

проблема была решена.

person garnet    schedule 22.10.2015

Вы добавили BouncyCastle к поставщикам безопасности? Вы можете сделать это с помощью этой строки:

Security.addProvider(new BouncyCastleProvider());
person Johnny Graber    schedule 08.01.2012
comment
Да, я это сделал, но я не скопировал его во фрагменте, который я разместил здесь. Я обновлю его. - person Guus; 08.01.2012

Вы можете добавить 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 и ниже строки

security.provider.1=sun.security.provider.Sun

добавить вашего провайдера BC

security.provider.2=org.bouncycastle.jce.provider.BouncyCastleProvider

Измените количество провайдеров отдыха. Весь блок провайдеров должен быть похож на:

security.provider.1=sun.security.provider.Sun
security.provider.2=org.bouncycastle.jce.provider.BouncyCastleProvider
security.provider.3=sun.security.rsa.SunRsaSign
security.provider.4=sun.security.ec.SunEC
security.provider.5=com.sun.net.ssl.internal.ssl.Provider
security.provider.6=com.sun.crypto.provider.SunJCE
security.provider.7=sun.security.jgss.SunProvider
security.provider.8=com.sun.security.sasl.Provider
security.provider.9=org.jcp.xml.dsig.internal.dom.XMLDSigRI
security.provider.10=sun.security.smartcardio.SunPCSC
person Krzysztof Szewczyk    schedule 01.07.2013