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

[iaik-jce] How to retrieve private key from PKCS#12 file in applet ?



Hello !

I would like to extract private key from PKCS#12 file.

The private key can be obtained successfully in the JAVA Application.
By using the same code in the Applet, following error is prompted:

iaik.pkcs.PKCSException: iaik.java.security.NoSuchAlgorithmException:
Algorithm
PBE not implemented.
        at iaik.pkcs.pkcs12.PKCS12.decrypt(PKCS12.java)
        at ReadFileNS.readPKCS12(ReadFileNS.java:72)
        at ReadFileNS.init(ReadFileNS.java:46)
        at sun.applet.AppletPanel.run(AppletPanel.java:344)
        at java.lang.Thread.run(Thread.java:484)

I try to use application libraries, instead of applet libraries. Same error
is returned.

Please tell me what's going wrong. And tell me how to solve this problem.

Thanks in advanced.

Regards,
Joyce

--------------------------
My program code for reference:

public class ReadFileNS extends Applet {
  public void init() {
    try {
      StringWriter sw = new StringWriter();
      sw.write("Hello\n");

    	java.security.interfaces.RSAPrivateKey privKey = null;
      PKCS12 p12 = new PKCS12(new FileInputStream(PFX));
      if (p12 != null) {
        p12.decrypt(password);
        KeyBag kBag = p12.getKeyBag();

        if (kBag != null)
          privKey = (java.security.interfaces.RSAPrivateKey)
kBag.getPrivateKey();
	    if (privKey != null) {
		System.out.println(privKey.getModulus());
		sw.write("Modulus of Private Key: " + privKey.getModulus() + "\n");
	    }
        }
	}

      setLayout (new BorderLayout());
      add (new TextArea (sw.toString()), BorderLayout.CENTER);
    } catch (IOException e) {
      System.err.println ("Error reading file");
    } catch (Exception ex) {
      ex.printStackTrace();
    }
  }
}

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