Hi
When i am creating a signature using openssl and verifying using rsa_verify
I am getting Invalid RSA signature format.
Please find the steps followed.
Create a file containing all lower case alphabets
echo abcdefghijklmnopqrstuvwxyz > myfile.txt
Generate 1024 bit Private key
openssl genrsa -out myprivate.pem 1024
Separate the public part from the Private key file.
openssl rsa -in myprivate.pem -pubout > mypublic.pem
Sign the file using sha256 digest and PKCS1 padding scheme
openssl dgst -sha256 -sign myprivate.pem -out myfile.txt.sig myfile.txt
Verify the signature of file
openssl dgst -sha256 -verify mypublic.pem -signature myfile.txt.sig myfile.txt
#output
#Verified OK
check the sha256 hash value
openssl dgst -sha256 myfile.txt
<<COMMENT1
SHA256(myfile.txt)= 1010a7e761610980ac591359c871f724de150f23440ebb5959ac4c0724c91d91
COMMENT1
check the signature
openssl rsautl -verify -inkey myprivate.pem -in myfile.txt.sig -raw -hexdump
: ’
0000 - 00 01 ff ff ff ff ff ff-ff ff ff ff ff ff ff ff …
0010 - ff ff ff ff ff ff ff ff-ff ff ff ff ff ff ff ff …
0020 - ff ff ff ff ff ff ff ff-ff ff ff ff ff ff ff ff …
0030 - ff ff ff ff ff ff ff ff-ff ff ff ff ff ff ff ff …
0040 - ff ff ff ff ff ff ff ff-ff ff ff ff 00 30 31 30 …010
0050 - 0d 06 09 60 86 48 01 65-03 04 02 01 05 00 04 20 …`.H.e…
0060 - 10 10 a7 e7 61 61 09 80-ac 59 13 59 c8 71 f7 24 …aa…Y.Y.q.$
0070 - de 15 0f 23 44 0e bb 59-59 ac 4c 07 24 c9 1d 91 …#D…YY.L.$…
’
#Generating the N and E
./key_app mode=private filename=myprivate.pem > rsa_priv.txt
#remove first 3 lines in the rsa_priv.txt
sed -i ‘1,3d’ rsa_priv.txt
#dos2unix
dos2unix rsa_priv.txt
#creating the rsa_pub.txt, deleting the 3 to 8 lines in the rsa_private.txt and redirecting to rsa_pub.txt
sed ‘3,8d’ rsa_priv.txt>temp.txt; mv temp.txt rsa_pub.txt
#Verfiying the with rsa_verify
./rsa_verify myfile.txt
. Reading public key from rsa_pub.txt
! Invalid RSA signature format
But i am able to verify the signature when i am creating the signature using rsa_sign.
I am not sure what is problem, when i am creating the signature using openssl.