How do you convert a JCE algorithm name into an Al

2019-07-28 09:28发布

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条回答
来,给爷笑一个
2楼-- · 2019-07-28 10:04

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
查看更多
登录 后发表回答