How to read a password encrypted key with java?
Posted
by Denis
on Stack Overflow
See other posts from Stack Overflow
or by Denis
Published on 2010-04-16T17:23:02Z
Indexed on
2010/04/17
15:03 UTC
Read the original article
Hit count: 327
Hi, This is very simple question. I have private key stored in file in PKCS8 DER format and protected by password. What is the easiest way to read it?
Here is the code I use to load unencrypted one:
InputStream in = new FileInputStream(privateKeyFilename);
byte[] privateKeydata = new byte[in.available()];
in.read(privateKeydata);
in.close();
KeyFactory privateKeyFactory = KeyFactory.getInstance("RSA");
PKCS8EncodedKeySpec encodedKeySpec = new PKCS8EncodedKeySpec(privateKeydata);
PrivateKey privateKey = privateKeyFactory.generatePrivate(encodedKeySpec);
Please, Help!!!
© Stack Overflow or respective owner