Multiple OpenSSL RSA signing methods produce different results

后端 未结 1 1808
天命终不由人
天命终不由人 2020-11-29 11:47

Trying to wrap my head around signing and use/test various options.

I can sign using this command:

openssl dgst -sha256 -sign private_key.pem -binary         


        
相关标签:
1条回答
  • 2020-11-29 12:20

    Dupe: Difference between openSSL rsautl and dgst
    Closely related:
    Why are the RSA-SHA256 signatures I generate with OpenSSL and Java different?
    Different signatures when using C routines and openssl dgst, rsautl commands
    Signing 20-byte message with 256-bit RSA key working with openssl.exe but not in code
    Crossdupe: https://superuser.com/questions/943972/what-is-the-difference-between-openssl-pkeyutl-sign-and-openssl-rsautl-sign

    TLDR: dgst -sign for RSA does the full RSASSA-PKCS1-v1_5: hash the data, encode the hash in ASN.1, pad the result, and modexp d. rsautl -sign does only the last two and dgst by itself only the first, thus skipping the encode producing a different and nonstandard signature. dgst (or your own hash) then pkeyutl -sign with an RSA key and -pkeyopt digest:name_of_digest (important!) also works and answers your real question.

    0 讨论(0)
提交回复
热议问题