如何存储/检索 RSA 公钥/私钥

How to store/retrieve RSA public/private key(如何存储/检索 RSA 公钥/私钥)
本文介绍了如何存储/检索 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 公钥/私钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)