Quantcast
Channel: .NET Private Key Rsa Encryption - Stack Overflow
Viewing all articles
Browse latest Browse all 3

Answer by President James K. Polk for .NET Private Key Rsa Encryption

$
0
0

You should be aware of the Bouncycastle C# library. There are in particular two very useful classes: Org.BouncyCastle.OpenSsl.PemReader which will convert from the openssl style key you have to a bouncycastle key object, and Org.BouncyCastle.Security.DotNetUtilities, which will convert a bouncycastle key to a .NET RSAParameters object.

Here is a tiny bit of untested code that shows how to use it

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);        }    }}

Viewing all articles
Browse latest Browse all 3

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>