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

[iaik-jce] How to get RSAPrivate Key from PKCS#12 file, instead of Private Key ?



Hi all,

Since I would like to get modulus and exponent of RSA private key, I must
get RSAPrivateKey object from PKCS#12, instead of PrivateKey object.

I can get PrivateKey object:
	PKCS12 p12 = new PKCS12(new FileInputStream(PFXname));
      p12.decrypt(password);
      KeyBag kBag = p12.getKeyBag();
      PrivateKey privKey = (PrivateKey) (kBag != null ? kBag.getPrivateKey()
: null);
      if (privKey != null){
      	System.out.println(privKey);
      }

But, an error "java.lang.ClassCastException:
com.sun.rsajca.JSA_RSAPrivateKey " occurs if RSAPrivateKey class is casted.
	PKCS12 p12 = new PKCS12(new FileInputStream(PFXname));
      p12.decrypt(password);
      KeyBag kBag = p12.getKeyBag();
      RSAPrivateKey privKey = (RSAPrivateKey) (kBag != null ?
kBag.getPrivateKey() : null);
      if (privKey != null){
      	System.out.println(privKey);
      }

Does anyone know how to get ?
Please kindly advise.

Thanks in advanced.

Best Regards,
Joyce

--
Mailinglist-archive at
http://jcewww.iaik.at/mailarchive/iaik-jce/jcethreads.html

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