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

[iaik-ssl] Set a PKCS#12 file from an IAIK keystore



Hi,

I have some problems to set a PKCS12 file from an IAIK keystore. The
following code works fine.
But when i tried to use the MS assistant tool to import the PKCS12 file
in the MS Keystore i get an error at the end of the import
processus : "input informations are not valid " (in French : "les
informations entres ne sont pas valides.") . All the beginning
of the MS import assistant tool is OK (Reading of the file, decryption
of the password file, .....).
why MS does not reconize my PKCS12 file ???

Thanks all for your help :

My code :

//Keystore location
 String keyStoreFile="d:\\IAIKkeystore";

 //Creation  Keystore object
 KeyStore ks= KeyStore.getInstance("IAIKKeyStore");
 ks.load(new FileInputStream(keyStoreFile), "penelope".toCharArray());

 //Read private key :  "cmuttest.com"
 PrivateKey pk =
(PrivateKey)ks.getKey("certTest","penelope".toCharArray());
 if (pk != null)
  System.out.println("Algo Private Key : " + pk.getAlgorithm() + "
........");
 else
  System.out.println("Private Key is NULL ................");

 //Read certificats chain : "cmuttest.com"
 iaik.x509.X509Certificate[]
tab_cert=(iaik.x509.X509Certificate[])ks.getCertificateChain("certTest");

 System.out.println("SUBJECT cert 0 : " +
(tab_cert[0].getSubjectDN()).getName() + "..............");
 System.out.println("ISSUER cert 0 : " +
(tab_cert[0].getIssuerDN()).getName() + "..............");
 System.out.println("SUBJECT cert 1 : " +
(tab_cert[1].getSubjectDN()).getName() + "..............");
 System.out.println("ISSUER cert 1 : " +
(tab_cert[1].getIssuerDN()).getName() + "..............");

 // DUMP KEYSTORE to P12
//pkcs12 location
 String myP12File="d:\\certtest.pfx";

//set Keybag and CertificateBag
KeyBag myKeyBag=new KeyBag(pk);
CertificateBag myCertBag[] = new CertificateBag[2];
 myCertBag[0]= new CertificateBag(tab_cert[0]);
 myCertBag[1]=new CertificateBag(tab_cert[1]);
 System.out.println("SUBJECT cert 0 : " +
(myCertBag[0].getCertificate().getSubjectDN()).getName() +
"..............");
 System.out.println("SUBJECT cert 1 : " +
(myCertBag[1].getCertificate().getSubjectDN()).getName() +
"..............");

//new pkcs12 object
PKCS12 myP12 = new PKCS12(myKeyBag, myCertBag);
 myP12.encrypt("penelope".toCharArray());

//dump
 FileOutputStream fos = new FileOutputStream(myP12File);
 myP12.writeTo(fos);
 fos.flush();
 fos.close();


FRED :-(
begin:vcard 
n:Felten;Frédéric
tel;work:02.40.18.25.48
x-mozilla-html:FALSE
org:CMLACO;CMILACO
adr:;;;NANTES;;44000;France
version:2.1
email;internet:frederic.felten@cmutweb.com
x-mozilla-cpt:;-16832
fn:Frédéric Felten
end:vcard