How to verify a signature programmatically
To learn how to verify signatures programmatically, let’s develop a small ec-verify
program that can verify signatures produced by ec-sign
or openssl pkeyutl
.
Our program will take three command-line arguments:
- The name of the input file containing the signed data
- The name of the file containing the signature
- The name of the file containing the verifying public key
Here is our high-level implementation plan for the program:
- Load the signature.
- Load the verifying public key.
- Create an
EVP_MD_CTX
object that will be used as the verifying context. - Initialize the verifying context with the hash function’s name and the loaded public key.
- Read the signed data chunk by chunk and feed it to the verifying context.
- Finalize the verification and find out whether the verification has succeeded or failed.
Now it’s time to implement our plan.