views:

45

answers:

1

I've created an RSA key pair using OpenSSL. The private key file is DER encoded. I need to load this file into my Java app and sign some data. Here's what I have:

byte[] private_key = new byte[] ...

... load bytes from file into private_key ..

PKCS8EncodedKeySpec pkcs8_key_spec = new PKCS8EncodedKeySpec( private_key );
KeyFactory key_factory = KeyFactory.getInstance( "RSA" );
rsa_key = (RSAPrivateKey) key_factory.generatePrivate( pkcs8_key_spec );

Signature signature = Signature.getInstance( "SHA1withRSA" );
signature.initSign( rsa_key );
signature.update( original_message.getBytes( "UTF8" ) );
sig = signature.sign();

... 
write sig to output file.

Once the file is written I attempt to verify the signature with OpenSSL:

$ openssl dgst -sha1 -verify public.pem -signature output.txt original_message.txt
$ Verification Failure

The verification fails. I'm not sure where I'm going wrong.

TIA

A: 

Got it figured out. Thanks.

Tim
Please post your solution (as part of this answer) for the benefit of the community.
Jim Garrison