# Reading a SSLEAY Private key.

Arjun Khanna (arjun@jump.net)
Mon, 05 Oct 1998 21:29:20 -0500

- Messages sorted by: [ date ][ thread ][ subject ][ author ]
- Next message: Nadal, Bill: "Errors"
- Previous message: David Brownell: "Re: Java Client/SSL.jar interop problems with SSLEAY."

--=====================_907658960==_
Content-Type: text/plain; charset="us-ascii"

Hi Jeff:
I am mailing you a small Java file which I am using to read a private key.
The private key is generated via the same ssleay script I mailed you
earlier this am. Namely:

I generate a new private key and cert request using the following command:
E:\usr\local\ssl\bin> ssleay req -new -nodes -days 365 -keyout newkey.pem
-newkey dsa:CAfiles/CAcert.pem -out newreq.pem

I did not password protect the key file which is done using the ssleay step:
ssleay dsa -in newkey.pem -out newkey.pem -des

next I convert the pem private key file- newkey.pem into its DER
equivalent. using:
ssleay dsa -in newkey.pem -out newkey.der -outform DER

Then I try and load the file newkey.der into a small java program Pkey.java
- file attached. I get an exception:
e:\jdk1.2beta4\bin\java -classpath
e:\Hotjava\lib\ssl.jar;e:\Hotjava\lib\x509v1.jar;. Pkey
e:\usr\local\ssl\bin\newkey.der

Bytes available = 251
Private key file read 251 bytes
Exception msg = Inappropriate key specification
java.security.spec.InvalidKeySpecException: Inappropriate key specification
at
sun.security.provider.DSAKeyFactory.engineGeneratePrivate(DSAKeyFactory.java
:105)
at java.security.KeyFactory.generatePrivate(KeyFactory.java:199)
at Pkey.main(Pkey.java:23)

Am I going off on a wrong tangent in the file Pkey.java? Curious. I was
able to take a SSLEAY generated certificate in .pem format and convert it
to a DER format cert (using SSLEAY). I could read the certificate using
JDK1.2beta4,just fine. And I could print out the public key also (that file
Cert.java and the der certificate is also attached).

Thanks a lot for any assistance.

-Arjun
I attached the Pkey.java file and the newkey.der file in a zip file. The
File Cert.java should be run with server_dsa_cert.der
--=====================_907658960==_
Content-Type: application/zip; name="pkey.zip";
x-mac-type="705A4950"; x-mac-creator="705A4950"
Content-Disposition: attachment; filename="pkey.zip"
Content-Transfer-Encoding: base64

UEsDBBQAAAAI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56GXIHU68sUND7DTFa4FWbe4+bwNpt00n+/Dn+HIuSDFJwQQpdeOoDzEmmufWVaIOsy
9CYdkovKOGTZJDUUVpyaWKJYXfNK3vuJsF5XtI5Q5aahvPY9UqXZwdy5Bi1IB0dwAD+TQUgf8dNL
ln2vL5q7RxT02WAd+A8HWWpOjcXjqjT+DZcKLrnCoZ0sfTwEkl/nuIiveIEt1Cu/TTeCTWBrAKfF
8YJbrhzU3Pp9CowFrKNmwSOL6kj7MNpdtS9SkdEtyvY1ezUQXO0TnA8E5x/b3yXp5zhNWt9UkG7w
fTlnxipOA3UCt7O/pcN/WLFkZy8Ca5JGA2av35n3RIXO8RJTg/HP/01IX19M8RYSjkf+eAdQSwEC
MgsUAAAACABspkUldkzoYsYBAABJBAAAFwAAAAAAAAABACAAtoEAAAAASmF2YS9zZWN1cml0eS9Q
a2V5LmphdmFQSwECMgsKAAAAAAAUgUUl8WZM1vsAAAD7AAAAHAAAAAAAAAAAACAAtoH7AQAAdXNy
L2xvY2FsL3NzbC9iaW4vbmV3a2V5LmRlclBLAQIyCxQAAAAIAAtgQSX5yH8p7gEAAGMCAAAlAAAA
AAAAAAAAIAC2gTADAAB1c3IvbG9jYWwvc3NsL2Jpbi9zZXJ2ZXJfZHNhX2NlcnQuZGVyUEsBAjIL
FAAAAAgA8aNFJQcDEJa/AQAAuwQAABcAAAAAAAAAAQAgALaBYQUAAEphdmEvc2VjdXJpdHkvQ2Vy
dC5qYXZhUEsFBgAAAAAEAAQAJwEAAFUHAAAAAA==
--=====================_907658960==_--

- Next message: Nadal, Bill: "Errors"
- Previous message: David Brownell: "Re: Java Client/SSL.jar interop problems with SSLEAY."