@@ -29,15 +29,22 @@ public class JcaPEMKeyConverter
2929{
3030 private JcaJceHelper helper = new DefaultJcaJceHelper ();
3131
32- private static final Map algorithms = new HashMap ();
32+ private final Map algorithms = new HashMap ();
33+
34+ private static final Map baseMappings = new HashMap ();
3335
3436 static
3537 {
36- algorithms .put (X9ObjectIdentifiers .id_ecPublicKey , "ECDSA" );
37- algorithms .put (PKCSObjectIdentifiers .rsaEncryption , "RSA" );
38- algorithms .put (X9ObjectIdentifiers .id_dsa , "DSA" );
38+ baseMappings .put (X9ObjectIdentifiers .id_ecPublicKey , "ECDSA" );
39+ baseMappings .put (PKCSObjectIdentifiers .rsaEncryption , "RSA" );
40+ baseMappings .put (X9ObjectIdentifiers .id_dsa , "DSA" );
3941 }
4042
43+ public JcaPEMKeyConverter ()
44+ {
45+ this .algorithms .putAll (baseMappings );
46+ }
47+
4148 public JcaPEMKeyConverter setProvider (Provider provider )
4249 {
4350 this .helper = new ProviderJcaJceHelper (provider );
@@ -52,6 +59,27 @@ public JcaPEMKeyConverter setProvider(String providerName)
5259 return this ;
5360 }
5461
62+ /**
63+ * Set the algorithm mapping for a particular OID to the given algorithm name.
64+ *
65+ * @param algOid object identifier used to identify the public/private key
66+ * @param algorithmName algorithm name we want to map to in the provider.
67+ * @return the current builder instance.
68+ */
69+ public JcaPEMKeyConverter setAlgorithmMapping (ASN1ObjectIdentifier algOid , String algorithmName )
70+ {
71+ this .algorithms .put (algOid , algorithmName );
72+
73+ return this ;
74+ }
75+
76+ /**
77+ * Convert a PEMKeyPair into a KeyPair, returning the converted result.
78+ *
79+ * @param keyPair the PEMKeyPair to be converted.
80+ * @return the result of the conversion
81+ * @throws PEMException if an exception is thrown attempting to do the conversion.
82+ */
5583 public KeyPair getKeyPair (PEMKeyPair keyPair )
5684 throws PEMException
5785 {
0 commit comments