Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get an object identifier for a hash algorithm name in Java

I have to perform conversions between cryptography algorithms names and their object identifiers (OIDs). I use Java Cryptography Architecture (JCA) and Bouncy Castle as a security provider. Converting OIDs to textual names is fairly easy with JCA itself.

String oid = "2.16.840.1.101.3.4.2.4";
MessageDigest md = MessageDigest.getInstance(oid);
String digestAlgorithmName = md.getAlgorithm();

But how do I perform backward conversion from textual names to OIDs? There seems to be no way how to get aliases for algorithm name in JCA. Bouncy Castle 1.50 has maps, which connect algorithm names to OIDs, but all of them have restricted access.

like image 704
divanov Avatar asked Jan 17 '14 16:01

divanov


1 Answers

There are a few helper classes in the PKIX distribution which are specifically for dealing with this.

Have a look in org.bouncycastle.operator - DefaultDigestAlgorithmIdentifierFinder and DefaultSignatureAlgorithmIdentifierFinder. There's also a few others in different places through the rest of the distribution.

like image 111
David Hook Avatar answered Sep 20 '22 21:09

David Hook