问题
I'm using BouncyCastle 1.54.
I have a JCE algorithm string - like "ECDSAwithSHA256" (for example).
I need an org.bouncycastle.asn1.x509.AlgorithmIdentifier object.
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.
I could create a giant if/else, but there's got to be a standard way to do this.
回答1:
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);
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
来源:https://stackoverflow.com/questions/38273270/how-do-you-convert-a-jce-algorithm-name-into-an-algorithmidentifier-object