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

VerifyData using loaded PEM fails #27

@sjmorgan81

Description

@sjmorgan81

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);

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions