Verifying a SHA1 Digest from a text string
I'm having a probl开发者_开发问答em verifying a SHA1 digest in base64 of a text string.
I have this text string in a file (test1):
2008-03-10;2008-03-10T15:58:00;FT 1/1;28.07;
And I used the follow command to encoded it (remember that I am encoding the text string not the text file per se):
openssl dgst -sha1 -sign Private_key.pem < test1 | openssl enc -base64 > hash1
Which results in the follow digest:
F8952fjEClltx2tF9m6/QTFynFjSuiboMslNZ1ag9oR5iIivgYYa0cNa0wJeWXlsf8QQVHUol303hp7XmIy5/kFOiV0v8QH6SF0Q5zNsDtpeFh2ZJ256y0DkJMSQqCq3oSka+9zIXXRkXgEsSv6VScCYv8VTlIcGjsablpR6A4=
Now I want to verify this digest using the Public Key, however the command that I used was an example giving in the openssl how-to:
openssl dgst -sha1 -verify Public_key.pem -signature hash1 test1
But this always give me "Verification Failure".
Note: The hash1 file does not have any \n and the test1 file contains the string which was encoded.
openssl dgst -sha1 -verify Public_key.pem -signature hash1 test1
I am not familiar with openssl, but I don't see any parameter in the above command that would indicate that the hash file is encoded with base64. Perhaps you should convert the base64 encoded file into binary before verifying it?
you should base64 docode first
openssl dgst -sha1 -verify Public_key.pem -signature hash1_decoded test1
精彩评论