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

[iaik-jce] PKCS12 and Netscape



Hi,

I wrote a method that loads an .p12 file exported from Netscape and
generates an new .p12 file with the same contents, using the class PKCS12.
However Netscape could not be able to read the new file. Does anyone hava a
solution for it?

The following code shows how I did it:

private void decodePKCS12(String filename, String passwd) {
    try {
      PKCS12 pk = new PKCS12(new FileInputStream(filename));
      pk.decrypt(passwd.toCharArray());
      KeyBag kb = pk.getKeyBag();
      CertificateBag[] cb = pk.getCertificateBags();
      X509Certificate x509 = cb[0].getCertificate();
      CertificateBag[] cb2 = new CertificateBag[1];
      cb2[0] = new CertificateBag(cb[0].getCertificate());
      PKCS12 pkcs12 = new PKCS12(kb, cb2);
      pkcs12.encrypt(passwd.toCharArray());
      pkcs12.writeTo(new FileOutputStream("teste.p12"));
    }
    catch (Exception ex) {
      ex.printStackTrace();
      try {
        System.in.read();
      }
      catch (Exception exc) {}
    }
  }

Thanks in advance,

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