Вам следует знать о библиотеке Bouncycastle C # . В частности, есть два очень полезных класса: Org.BouncyCastle.OpenSsl.PemReader
, которые преобразуют из имеющегося у вас ключа стиля openssl в объект ключа bouncycastle, и Org.BouncyCastle.Security.DotNetUtilities
, который преобразует ключ bouncycastle в объект .NET RSAParameters
.
Вот небольшой кусочек непроверенного кода, который показывает, как его использовать
using System;
using System.IO;
using System.Security.Cryptography;
using Org.BouncyCastle.OpenSsl;
using Org.BouncyCastle.Crypto;
using Org.BouncyCastle.Security;
using Org.BouncyCastle.Crypto.Parameters;
namespace RSAOpensslToDotNet
{
class Program
{
static void Main(string[] args)
{
StreamReader sr = new StreamReader("../../privatekey.pem");
PemReader pr = new PemReader(sr);
AsymmetricCipherKeyPair KeyPair = (AsymmetricCipherKeyPair)pr.ReadObject();
RSAParameters rsa = DotNetUtilities.ToRSAParameters((RsaPrivateCrtKeyParameters)KeyPair.Private);
}
}
}