问题描述
我正在使用BouncyCastle 1.54。
I'm using BouncyCastle 1.54.
我有一个JCE算法字符串-例如 ECDSAwithSHA256。
I have a JCE algorithm string - like "ECDSAwithSHA256" (for example).
我需要一个org.bouncycastle.asn1.x509.AlgorithmIdentifier对象。
I need an org.bouncycastle.asn1.x509.AlgorithmIdentifier object.
或者,我可以从OID创建AlgorithmIdentifier对象,但是
Alternatively, I could create an AlgorithmIdentifier object from an OID, but that begs the question of how to translate an algorithm string into an OID instead.
我可以创建一个巨大的if / else,但是必须有一种标准的方法来实现。
I could create a giant if/else, but there's got to be a standard way to do this.
推荐答案
您可以使用BouncyCastle的算法查找器(请参见)
You can use the algorithm finders of BouncyCastle (see javadoc)
import org.bouncycastle.operator.DefaultDigestAlgorithmIdentifierFinder;
import org.bouncycastle.operator.DefaultSignatureAlgorithmIdentifierFinder;
AlgorithmIdentifier sigAlgId = new DefaultSignatureAlgorithmIdentifierFinder().find(signatureAlgorithm);
AlgorithmIdentifier digAlgId = new DefaultDigestAlgorithmIdentifierFinder().find(sigAlgId);
AlgorithmIdentifier
为<$ c获得的OID $ c> SHA256withECDSA (不是 ECDSAwithSHA256
,请参见)将是
The AlgorithmIdentifier
OID's obtained for SHA256withECDSA
(not ECDSAwithSHA256
, see bouncycastle specifications) will be
1.2.840.10045.4.3.2
2.16.840.1.101.3.4.2.1
这篇关于如何将JCE算法名称转换为AlgorithmIdentifier对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!