@@ -340,7 +340,7 @@ else if ( line.indexOf(BEG_STRING_DSA) != -1 ) {
340
340
}
341
341
else if ( line .indexOf (BEG_STRING_ECPRIVATEKEY ) != -1 ) {
342
342
try {
343
- return readKeyPair (reader , passwd , "ECDSA " , BEF_E + PEM_STRING_ECPRIVATEKEY );
343
+ return readKeyPair (reader , passwd , "EC " , BEF_E + PEM_STRING_ECPRIVATEKEY );
344
344
}
345
345
catch (Exception e ) {
346
346
throw mapReadException ("problem creating DSA private key: " , e );
@@ -349,9 +349,10 @@ else if ( line.indexOf(BEG_STRING_ECPRIVATEKEY) != -1) {
349
349
else if ( line .indexOf (BEG_STRING_PKCS8INF ) != -1 ) {
350
350
try {
351
351
byte [] bytes = readBase64Bytes (reader , BEF_E + PEM_STRING_PKCS8INF );
352
- PrivateKeyInfo info = PrivateKeyInfo .getInstance (bytes );
353
- String type = getPrivateKeyTypeFromObjectId (info .getPrivateKeyAlgorithm ().getAlgorithm ());
354
- return org .jruby .ext .openssl .impl .PKey .readPrivateKey (((ASN1Object ) info .parsePrivateKey ()).getEncoded (ASN1Encoding .DER ), type );
352
+ PrivateKeyInfo pInfo = PrivateKeyInfo .getInstance (bytes );
353
+ KeyFactory keyFactory = getKeyFactory ( pInfo .getPrivateKeyAlgorithm () );
354
+ PrivateKey pKey = keyFactory .generatePrivate (new PKCS8EncodedKeySpec (pInfo .getEncoded ()));
355
+ return new KeyPair (null , pKey );
355
356
}
356
357
catch (Exception e ) {
357
358
throw mapReadException ("problem creating private key: " , e );
@@ -605,7 +606,7 @@ public static ECPublicKey readECPubKey(Reader in) throws IOException {
605
606
while ( ( line = reader .readLine () ) != null ) {
606
607
if ( line .indexOf (BEG_STRING_EC_PUBLIC ) != -1 ) {
607
608
try {
608
- return (ECPublicKey ) readPublicKey (reader , "ECDSA " , BEF_E + "EC PUBLIC KEY" );
609
+ return (ECPublicKey ) readPublicKey (reader , "EC " , BEF_E + "EC PUBLIC KEY" );
609
610
}
610
611
catch (Exception e ) {
611
612
throw mapReadException ("problem creating ECDSA public key: " , e );
@@ -621,7 +622,7 @@ public static ECPublicKey readECPublicKey(final Reader in, final char[] passwd)
621
622
while ( ( line = reader .readLine () ) != null ) {
622
623
if ( line .indexOf (BEG_STRING_PUBLIC ) != -1 ) {
623
624
try {
624
- return (ECPublicKey ) readPublicKey (reader , "ECDSA " , BEF_E + PEM_STRING_PUBLIC );
625
+ return (ECPublicKey ) readPublicKey (reader , "EC " , BEF_E + PEM_STRING_PUBLIC );
625
626
}
626
627
catch (Exception e ) {
627
628
throw mapReadException ("problem creating ECDSA public key: " , e );
@@ -638,7 +639,7 @@ public static KeyPair readECPrivateKey(final Reader in, final char[] passwd)
638
639
while ( ( line = reader .readLine () ) != null ) {
639
640
if ( line .indexOf (BEG_STRING_EC ) != -1 ) {
640
641
try {
641
- return readKeyPair (reader , passwd , "ECDSA " , BEF_E + "EC PRIVATE KEY" );
642
+ return readKeyPair (reader , passwd , "EC " , BEF_E + "EC PRIVATE KEY" );
642
643
}
643
644
catch (Exception e ) {
644
645
throw mapReadException ("problem creating ECDSA private key: " , e );
@@ -1171,6 +1172,8 @@ public static void writeDHParameters(Writer _out, DHParameterSpec params) throws
1171
1172
private static String getPrivateKeyTypeFromObjectId (ASN1ObjectIdentifier oid ) {
1172
1173
if ( ASN1Registry .oid2nid (oid ) == ASN1Registry .NID_rsaEncryption ) {
1173
1174
return "RSA" ;
1175
+ } else if ( ASN1Registry .oid2nid (oid ) == ASN1Registry .NID_X9_62_id_ecPublicKey ) {
1176
+ return "EC" ;
1174
1177
} else {
1175
1178
return "DSA" ;
1176
1179
}
@@ -1226,7 +1229,7 @@ private static PublicKey readPublicKey(BufferedReader in, String alg, String end
1226
1229
1227
1230
private static PublicKey readPublicKey (BufferedReader in , String endMarker ) throws IOException {
1228
1231
byte [] input = readBase64Bytes (in , endMarker );
1229
- String [] algs = { "RSA" , "DSA" , "ECDSA " };
1232
+ String [] algs = { "RSA" , "DSA" , "EC " };
1230
1233
for (int i = 0 ; i < algs .length ; i ++) {
1231
1234
PublicKey key = readPublicKey (input , algs [i ], endMarker );
1232
1235
if (key != null ) {
@@ -1488,7 +1491,7 @@ public static KeyFactory getKeyFactory(final AlgorithmIdentifier algId)
1488
1491
1489
1492
String algorithm = null ;
1490
1493
if ( X9ObjectIdentifiers .id_ecPublicKey .equals (algIdentifier ) ) {
1491
- algorithm = "ECDSA " ;
1494
+ algorithm = "EC " ;
1492
1495
}
1493
1496
else if ( PKCSObjectIdentifiers .rsaEncryption .equals (algIdentifier ) ) {
1494
1497
algorithm = "RSA" ;
0 commit comments