[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[iaik-jce] Private Key from PKCS12



Hi,

I am trying to obtain the private key from a .p12 file that I have
imported from Netscape 4.7 to 
sign a challenge of an authentication method.
I know the password that is used to protect that key.

When I obtain the KeyBag, format and algorithm, it says that it is a
PKCS8 structure and RSA algorithm.
But I want to obtain the decrypted private key from this PKCS8
structure.

My code is as follows:

FileInputStream fis=new FileInputStream("file.p12");
PKCS12 test=new PKCS12(fis);
System.out.println(test.toString());
String password="password";
test.decrypt(password.toCharArray());
KeyBag myKeyBag=test.getKeyBag();
System.out.println(myKeyBag.toString());
System.out.println(myKey.getAlgorithm());
System.out.println(myKey.getFormat());
PrivateKey myKey=miKeyBag.getPrivateKey();

But when I obtain the encoded private key it is 365 bytes long, not the
512-bit RSA key.
I think that I need to use the EncryptedPrivateKeyInfo class or the
PKCS8ShroudedKeyBag but I
don't know how. 
Please could somebody show me a piece of code to extract the byte[] key
from the PKCS8 structure
assuming that it is encrypted.

Thanks in advance.

Manuel Tascón
--
Mailinglist-archive at http://jcewww.iaik.tu-graz.ac.at/mailarchive/iaik-jce/maillist.html

To unsubscribe send an email to listserv@iaik.tu-graz.ac.at with the folowing content: UNSUBSCRIBE iaik-jce