Re: How to run C# Sample Code for MLE

vhuzov
Regular Visitor

Re: How to run C# Sample Code for MLE

Hi @asaldanha

 

I know it is too late but want to leave the solution for the next error   

 

Unable to cast object of type 'Org.BouncyCastle.X509.X509Certificate' to type 'Org.BouncyCastle.Crypto.AsymmetricCipherKeyPair'.

The code below resolve this error

 

   private static RSA ImportPrivateKey(string privateKeyFile)

{

        var pr = new PemReader(File.OpenText(privateKeyFile));

        var rsaPrivateKeyParameters = (RsaPrivateCrtKeyParameters)pr.ReadObject();
        var rsaParams = DotNetUtilities.ToRSAParameters(rsaPrivateKeyParameters);

        var rsa = RSA.Create();
        rsa.ImportParameters(rsaParams);

        return rsa;

}