Greg,
     Thanks for your help. I am using the Sun's classes for my application.
KeyStore keyStore;
byte[] bytes;
X509Certificate[] certs = new X509Certificate[2];

I am calling this function

keyStore.setKeyEntry("testKey", bytes, certs); and it is throwing 
exceptions.

java.lang.NullPointerException
        at 
sun.security.pkcs.EncryptedPrivateKeyInfo.<init>(EncryptedPrivateKeyInfo.java:63)
        at 
sun.security.provider.JavaKeyStore.engineSetKeyEntry(JavaKeyStore.java:275)
        at java.security.KeyStore.setKeyEntry(KeyStore.java:395)





List:     openssl-users
Subject:  Re: PKCS8 and JAVA Application
From:     "Greg Stark" <[EMAIL PROTECTED]>
Date:     2001-02-28 22:55:16
[Download message RAW]

Srini,

    What sorts of exceptions are you getting? Of course you need to use the
same password for reading the key in that you used to write it out. The
default encryption algorithm used by the pkcs8 utility is
pbeWithMD5AndDES-CBC, so this must be available to the Java code you are
importing the key with. Here is a very short example that uses the IAIK JCE
2.6 classes and provider.



/***
* Suppose the following commands are run:
* openssl genrsa -out key.pem
* openssl pkcs8 -topk8 -outform DER -in key.pem -out enckey.der -passout
pass:PASSWORD
* Then run this program as:
* java TestPKCS8 enckey.der PASSWORD
*/

import iaik.asn1.DerCoder;
import iaik.asn1.ASN1Object;
import iaik.pkcs.pkcs8.EncryptedPrivateKeyInfo;
import java.io.FileInputStream;
import java.security.PrivateKey;

public class TestPKCS8 {
public static void main(String [] args)
{
  try{
   iaik.security.provider.IAIK.addAsProvider();
   ASN1Object enckey = DerCoder.decode(new FileInputStream(args[0]));
   PrivateKey key = new EncryptedPrivateKeyInfo(enckey).decrypt(args[1]);
   System.out.println(key);
  } catch(Exception e) {
   e.printStackTrace();
  }
}
}

_____________________________________
Greg Stark
Ethentica, Inc.
[EMAIL PROTECTED]
_____________________________________



----- Original Message -----
From: "srinivasa siripurapu" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, February 28, 2001 8:25 PM
Subject: PKCS8 and JAVA Application


>Hi,
>         I am trying to load a private key into a java app using java
store,
>and it is unable to load it. i used this command toget my DER formatted
>private key.
>openssl  pkcs8 -outform DER -topk8 -in key.pem -out enckey.der
>
>when i try to load this i am encountering exceptions. Any suggestions?
>
>Thanks
>Srini
>_________________________________________________________________
>Get your FREE download of MSN Explorer at http://explorer.msn.com
>
>
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com

______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    [EMAIL PROTECTED]
Automated List Manager                           [EMAIL PROTECTED]

Reply via email to