Skip to content
This repository has been archived by the owner on Mar 20, 2023. It is now read-only.

VerifyData using loaded PEM fails #27

Open
sjmorgan81 opened this issue Mar 4, 2020 · 0 comments
Open

VerifyData using loaded PEM fails #27

sjmorgan81 opened this issue Mar 4, 2020 · 0 comments

Comments

@sjmorgan81
Copy link

sjmorgan81 commented Mar 4, 2020

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);
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants