如何从SSL密钥文件创建RsaSecurityKey实例

时间:2017-06-16 09:36:01

标签: c# rsa .net-core

我有RFC 7468中所述格式的RSA私钥,我使用的库需要SecurityKey的实例,没有任何构造函数似乎接受字符串在这种格式中,它的构造函数的任何可接受的参数似乎都不接受这种格式。

1 个答案:

答案 0 :(得分:3)

Found a Library that handles PEM Keys in .Net,如果同时包含DerConverter和PemUtils,您只需阅读该文件:

RsaSecurityKey key;
using (var stream = File.OpenRead(path))
using (var reader = new PemReader(stream))
{
    key = new RsaSecurityKey(reader.ReadRsaKey());
    // ...
}