At work, I have been assigned the task of using the OpenSSL command line (on my laptop in Cygwin) to create an RSA key pair in PEM format, and to encrypt a piece of plain data that will be decrypted by an older, legacy embedded system.
This all works fine with an RSA key pair that we inherited. However, I am having trouble trying to duplicate the process with my own OpenSSL key creation and encryption commands.
The OpenSSL commands I used to create the key pair and encrypt the plain data are:
I used the -traditional switch to create the RSA key pair because I read somewhere that it would produce the desired “RSA_PKCS1_PADDING” expected by the embedded system.
As a last resort, I am allowed to modify the embedded system to use other types of padding to get this working. The padding choices I have are:
If anyone could help me correct the two OpenSSL commands, I would really appreciate it. Thank you. I’m not very experienced in cryptography.
Edited to add this after the comment by dave_thompson_085
I changed my key creation commands and encryption (sign) command to the following:
I used this, and the decryption "worked", but the decrypted result was the SHA256 hash of the file. I need the file contents themselves encrypted/decrypted - not the SHA256 hash.
Can I adjust this command to work - to encrypt the file contents with the private key so that the embedded system decrypts with public key? I know I'm probably using the wrong terminology - encrypt vs sign - but I need the contents of the file encrypted, not its SHA256 hash.
Thanks.
At work, I have been assigned the task of using the OpenSSL command line (on my laptop in Cygwin) to create an RSA key pair in PEM format, and to encrypt a piece of plain data that will be decrypted by an older, legacy embedded system.
This all works fine with an RSA key pair that we inherited. However, I am having trouble trying to duplicate the process with my own OpenSSL key creation and encryption commands.
The OpenSSL commands I used to create the key pair and encrypt the plain data are:
I used the -traditional switch to create the RSA key pair because I read somewhere that it would produce the desired “RSA_PKCS1_PADDING” expected by the embedded system.
As a last resort, I am allowed to modify the embedded system to use other types of padding to get this working. The padding choices I have are:
If anyone could help me correct the two OpenSSL commands, I would really appreciate it. Thank you. I’m not very experienced in cryptography.
Edited to add this after the comment by dave_thompson_085
I changed my key creation commands and encryption (sign) command to the following:
I used this, and the decryption "worked", but the decrypted result was the SHA256 hash of the file. I need the file contents themselves encrypted/decrypted - not the SHA256 hash.
Can I adjust this command to work - to encrypt the file contents with the private key so that the embedded system decrypts with public key? I know I'm probably using the wrong terminology - encrypt vs sign - but I need the contents of the file encrypted, not its SHA256 hash.
Thanks.
I wanted to post that due to help from @dave_thompson_085, I was able to use the following to solve my problem:
openssl pkeyutl -sign -pkeyopt rsa_padding_mode:pkcs1 -inkey private.pem -in applicat_aes_key_iv.bin -out applicat_aes_key_iv.enc
Thanks Dave.
pkeyutl -sign
.PUBKEY
is a structure defined by the certificate standard X.509 (and its variant PKIX) hence 'certificate public key structure' but is not a certificate. ... – dave_thompson_085 Commented Feb 2 at 7:53genrsa -traditional
only affects how the privatekey is stored on YOUR system; it has no effect on operations using the key. Both the key format AND the padding for operations -- and more -- were defined by PKCS1 but are quite different and unrelated things. Andopenssl errstr 4067072
->rsa routines:rsa_ossl_public_decrypt:padding check failed
. – dave_thompson_085 Commented Feb 2 at 7:53pkeyutl -sign
which signs raw data (only up to the modulus size minus delta), notdgst -sign
which signs a hash of the (unbounded) data plus a prefix as described in e.g. rfc8017 section 9.2 at page 47 (this is the more usual and standard method for signing data) – dave_thompson_085 Commented Feb 2 at 20:55