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
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