Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you create an instance of RsaSecurityKey from a SSL key file

Tags:

c#

.net-core

rsa

I have a RSA private key in the format as stated in RFC 7468 and a library I'm using requires an instance of SecurityKey none of the constructor's seem to accept strings in this format, nor any of the accepted arguments for it's constructor seem to accept this format.

like image 653
DSUK Avatar asked Jan 18 '26 09:01

DSUK


1 Answers

Found a Library that handles PEM Keys in .Net, If you include both DerConverter and PemUtils you can simply read the file:

RsaSecurityKey key;
using (var stream = File.OpenRead(path))
using (var reader = new PemReader(stream))
{
    key = new RsaSecurityKey(reader.ReadRsaKey());
    // ...
}
like image 198
DSUK Avatar answered Jan 20 '26 23:01

DSUK



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!