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

AW: [iaik-jce] Need help putting my private key in a keystore


a short sample (look at
for more information):

         KeyStore keyStore = KeyStore.getInstance(keyStoreName, provider);
         keyStore.load(null, null);

         System.out.println("Store private key + cert chain...");
         keyStore.setKeyEntry("myEntry", privateKey, password, certs);

         System.out.println("Save keystore to file ...");
         FileOutputStream os = new FileOutputStream("...");
         keyStore.store(os, password);

          FileInputStream is = new FileInputStream("...");
         KeyStore keyStore1 = KeyStore.getInstance(keyStoreName, provider);
         keyStore1.load(is, password);

         // get key
         System.out.println("Fetching key...");
         try {
            Key key = keyStore1.getKey("myEntry", password);
            if (key != null) {
               System.out.println("Got key: " + key);
            } else {
               System.out.println("Missing key!");
         } catch (UnrecoverableKeyException ex) {
            System.out.println("Error in getting key: " + ex.getMessage());

         // get certificates
         System.out.println("Fetching certificates...");

         Certificate[] chain = keyStore1.getCertificateChain("myEntry");


         // clear password
         for (int i = 0; i < password.length; i++)
           password[i] = (char)0;

Dieter Bratko

-----Ursprüngliche Nachricht-----
Von: iaik-jce-owner@iaik.tu-graz.ac.at
[mailto:iaik-jce-owner@iaik.tu-graz.ac.at]Im Auftrag von Gert Verheyen
Gesendet: Donnerstag, 27. Juli 2000 15:16
An: 'iaik-jce@iaik.at'
Betreff: [iaik-jce] Need help putting my private key in a keystore

I have a problem with putting my private key that I obtained from a .pfx
file in a keystore.
When I want to add the keyentry to the keystore the following Exception is
java.security.UnrecoverableKeyException: Private key not stored as PKCS #8

Is there anyone who has ever done this succesfully, a little example program
would help a lot.  Thanks

Mailinglist-archive at

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