I'm trying to encrypt a string using a PEM public key file in dotnet core (1.1) and my question is: How do I do this?
I thought this would simply be a case of:
var cert = new X509Certificate2("path_to_public_key.pem");
using (var rsa = cert.GetRSAPublicKey())
{
// encrypt here
}
However, when I try to new up the certificate I get the following error:
error:0D07803A:asn1 encoding routines:ASN1_ITEM_EX_D2I:nested asn1 error
The PEM file looks like this:
-----BEGIN PUBLIC KEY-----
... ANBgkqhkiG9w0BAQEFA ...
(loads more text)
-----END PUBLIC KEY-----
I've checked the pem file and there are no extraneous ^M characters anywhere (as from a suggest cause of the error here).
(I'm on macOS Sierra if that makes any difference)
Any help would be greatly appreciated!