R – What format signature does Openssl pkeyutl expect

digital-signatureencryptionopensslrsa

I'm trying to verify a file that was signed by hashing with SHA-1 and encrypting the hash with an RSA private key.

Obviously I'm using the RSA public key to verify. The key is in DER format.

The signature verification works correctly using Java's Signature class.

The openssl command I'm trying (and the result) is:

       ~/Downloads/openssl-1.0.0-beta3/apps/openssl pkeyutl -in encryptedZip.bin 
-keyform DER -verify -sigfile savedDigitalSignature.txt -pubin -inkey public.der
    WARNING: can't open config file: /usr/local/ssl/openssl.cnf
    Signature Verification Failure

I don't see anything in the openssl configuration file that would apply, so I don't think that warning is significant.

The savedDigitalSignature.txt file contains the signature bytes.

My theory is that openssl is looking for the digital signature to be in some specific file format, but I haven't found anything in the documentation indicating what that should be.

Thoughts?

Best Answer

This command is very low level. You have to make sure everything is in the right format for it to work,

  1. The input signature (-sigfile) must be the binary signature. For RSA, the padding must be PKCS#1.
  2. The input data must be the binary digest. If you sign it with SHA1, this file can only contain 20 bytes.
  3. Public key must be in X.509 encoded SubjectPublicKeyInfo in DER or PEM format.
Related Topic