generate private key from a exist file

  • Thread starter Carla Schaffner
  • Start date
C

Carla Schaffner

Hi

i want to generate a private key from a exist file. i tried this but it
dosen't works!


---------Code--------------

FileInputStream keyfis = new FileInputStream("keyCarlaSchaffner.pem");
//"keyCarlaSchaffner.der"
byte[] encKey = new byte[keyfis.available()];
keyfis.read(encKey);
keyfis.close();

X509EncodedKeySpec privKeySpec = new X509EncodedKeySpec(encKey);

KeyFactory kf = KeyFactory.getInstance("RSA");
PrivateKey pk = kf.generatePrivate(privKeySpec);

---------Code end ----------

i have the private key file in pem and der encoded version, but both didn't
work.

PEM :

-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: DES-EDE3-CBC,F836EA29BA0C7925

.....
....
....
-----END RSA PRIVATE KEY-----

DER: no readable

the exception is:
--------------------------------

java.security.spec.InvalidKeySpecException: Key spec not RSA.
at
com.sun.net.ssl.internal.ssl.JSA_RSAKeyFactory.getPrivateKeyData(DashoA6275)
at
com.sun.net.ssl.internal.ssl.JS_KeyFactory.engineGeneratePrivate(DashoA6275)
at java.security.KeyFactory.generatePrivate(KeyFactory.java:237)
--------------------------------


has anyone a idea?

thanks carla
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,740
Latest member
JudsonFrie

Latest Threads

Top