如何存储/检索 RSA 公钥/私钥 [英] How to store/retrieve RSA public/private key

查看:65
本文介绍了如何存储/检索 RSA 公钥/私钥的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 RSA 公钥加密.存储或检索私钥和公钥的最佳方式是什么?XML 在这里是个好主意吗?

I want to use RSA public key encryption. What is the best way to store or retrieve private and public keys? Is XML a good idea here?

如何获得钥匙?

RSAParameters privateKey = RSA.ExportParameters(true);
RSAParameters publicKey = RSA.ExportParameters(false);

因为 RSAParameters 有以下成员:D, DP, DQ, Exponent, InverseQ, Modulus, P, Q

Because RSAParameters have the following members: D, DP, DQ, Exponent, InverseQ, Modulus, P, Q

哪一个是关键?

推荐答案

我成功的是将密钥存储为 XML.RSACryptoServiceProvider 中有两种方法:ToXmlString 和 FromXmlString.ToXmlString 将返回一个 XML 字符串,该字符串要么仅包含公钥数据,要么包含公钥和私钥数据,具体取决于您设置其参数的方式.当提供仅包含公钥数据或同时包含公钥和私钥数据的 XML 字符串时,FromXmlString 方法将使用适当的密钥数据填充 RSACryptoServiceProvider.

What I have done successfully is to store the keys as XML. There are two methods in RSACryptoServiceProvider: ToXmlString and FromXmlString. The ToXmlString will return an XML string containing either just the public key data or both the public and private key data depending on how you set its parameter. The FromXmlString method will populate the RSACryptoServiceProvider with the appropriate key data when provided an XML string containing either just the public key data or both the public and private key data.

这篇关于如何存储/检索 RSA 公钥/私钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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