This repository was archived by the owner on Mar 20, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 16
VerifyData using loaded PEM fails #27
Copy link
Copy link
Open
Labels
Description
I used the command-line OpenSSL program to generate the public and private keys and to sign a file but when I try to use RSA.VerifyData to verify the signature, it fails.
I was previously using the .NET Core version of the RSA class which has (slightly) better support for PEM and so didn't need to use PEM-utils and the VerifyData call succeeded.
I'm generating the keys like so:
> openssl version
OpenSSL 1.0.2u 20 Dec 2019
> openssl genpkey -out privkey.pem -algorithm rsa 4096
and the signature like so:
> openssl dgst -sha256 -sign privkey.pem -out test.zip.sig test.zip
and the code for verifying the signature looks like this:
var fileToVerifyStream = new FileStream(fileToVerifyPath, FileMode.Open);
byte[] signatureBytes = File.ReadAllBytes(fileSignaturePath);
RSAParameters publicKey = ReadPemPublicKey(publicKeyPath); // Calls PemReader.ReadRsaKey()
_rsa.ImportParameters(publicKey);
_rsa.VerifyData(fileToVerifyStream, signatureBytes, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);Reactions are currently unavailable