的RSACryptoServiceProvider和OpenSSL之间的互操作性 [英] Interoperability between RSACryptoServiceProvider and openSSL

查看:381
本文介绍了的RSACryptoServiceProvider和OpenSSL之间的互操作性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用了.NET类的RSACryptoServiceProvider 来得到一个密钥对:

I've used the .NET class RSACryptoServiceProvider to get a keypair:

using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider())
{
  File.WriteAllText ("PublicKeyOnly.xml", rsa.ToXmlString (false));
  File.WriteAllText ("PublicPrivate.xml", rsa.ToXmlString (true));
}

现在,我想在OpenSSH使用,但关键的格式看起来没事的一致好评。
有谁知道如何在公共和私有密钥转换为采用openSSH可以使用文件?

Now, I would like to use this with openSSH, but the key format looks nothing alike. Does anyone know how to convert both the public and private keys to files that openSSH can use?

谢谢!

推荐答案

我真的需要实现与的RSACryptoServiceProvider Openssl的互操作性,这样我就可以实现软件许可证密钥系统(的Ref )。

I really needed to achieve Openssl interoperability with RSACryptoServiceProvider, so that I could implement a software licence key system (Ref).

我需要的是能够使用OpenSSL创建,使Linux中的私钥和公钥他们后来在PHP Web应用程序可用于许可证管理。然而,也把它们作为一个VB.Net applciation的RSA签名许可证制度的基础。

I needed to be able to create the private and public keys in Linux using openssl so that they could later be used for license management in a PHP web application. Yet, also use them as the basis of an RSA signature license system in a VB.Net applciation.

搜索的一个星期后,我最终发现,这是完全有可能,所以我想我会分享它。

After a week of searching, I eventually discovered that this is perfectly possible, so I thought I would share it.

在Linux上启动(或任何其他有用OS)和使用OpenSSL创建一个私有密钥(private.pem),公共键(public.pem),产地证(certificate.crt)和个人信息交换文件(certificate.pfx)。不要担心CN和EMAILADDRESS领域,证书和PFX文件仅被用作交通工具,以获得公共或私人钥匙插入的RSACryptoServiceProvider对象。

Start on Linux (or any other useful OS) and use openssl to create a private key (private.pem), a public key (public.pem), a certificate (certificate.crt) and a Personal Information Exchange File (certificate.pfx). Don't worry about the CN and emailAddress fields, the certificate and pfx files are only being used as a vehicle to get the public or private key into the RSACryptoServiceProvider object.

openssl genrsa -out private.pem 1024
openssl rsa -in private.pem -out public.pem -pubout
openssl req -nodes -x509 -days 3650 -subj '/CN=www.example.com/emailAddress=info@example.com' -new -key private.pem -out certificate.crt
openssl pkcs12 -export -out certificate.pfx -inkey private.pem -in certificate.crt

现在得到私钥到代码:

Dim cert As New X509Certificate2("certificate.pfx", "", X509KeyStorageFlags.Exportable)
Dim rsaProvider As RSACryptoServiceProvider = DirectCast(cert.PrivateKey, RSACryptoServiceProvider)

如果您需要的私钥或公钥试试这个:

If you need the private key or public key try this:

msgbox(rsaProvider.ToXmlString(True))  'Private key in XML format
msgbox(rsaProvider.ToXmlString(False)) 'Public key in XML format

要获得公共密钥插入代码:

To get the public key into the code:

Dim cert As New X509Certificate2("certificate.crt")
Dim rsaProvider As RSACryptoServiceProvider = DirectCast(cert.PublicKey.Key, RSACryptoServiceProvider)

如果您需要的公共密钥试试这个:

If you need the public key try this:

msgbox(rsaProvider.ToXmlString(False))  'Public key in XML format

更多的惊喜......

More to come .....

这篇关于的RSACryptoServiceProvider和OpenSSL之间的互操作性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆