如何在.net Core中使用RSA [英] How to use RSA in .net Core

查看:941
本文介绍了如何在.net Core中使用RSA的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用 RSA 加密文件,但是它没有 toXmlString() fromXmlString 方法。如何在.net core中使用 RSA 类?
而且我想用私钥加密并用公钥解密,所以其他人只能读取此文件而不能生成此文件,这可能吗?

I try to encrypt a file with RSA, but it don't have the toXmlString() and fromXmlString method. how to use RSA class in .net core ? And I want to encrypt with private key and decrypt with public key ,so others can only read this file but can't generate this file , Is that possible ?

推荐答案

虽然 ToXmlString FromXmlString 方法不可用,但 ImportParameters(RSAParameters) ExportParameters(bool)是。

While the ToXmlString and FromXmlString methods are not available, ImportParameters(RSAParameters) and ExportParameters(bool) are.

如果您需要继续读取现有的XML格式值,则密钥的XML格式不是很有趣:

If you have existing XML formatted values that you need to continue to read, the XML format of the keys isn't very interesting:

仅公开:

<RSAKeyValue>
  <Modulus>[base64-encoded value]</Modulus>
  <Exponent>[base64-encoded value]</Exponent>
</RSAKeyValue>

公共+私人:

<RSAKeyValue>
  <Modulus>[base64-encoded value]</Modulus>
  <Exponent>[base64-encoded value]</Exponent>
  <P>[base64-encoded value]</P>
  <Q>[base64-encoded value]</Q>
  <DP>[base64-encoded value]</DP>
  <DQ>[base64-encoded value]</DQ>
  <InverseQ>[base64-encoded value]</InverseQ>
</RSAKeyValue>

(其中每个命名XML元素都映射到 RSAParameters 结构)

(where each named XML element maps to the field of the same name on the RSAParameters struct)

否则,您可以/应该使用最适合您和您的应用程序的任何序列化机制。

Otherwise you can/should use whatever serialization mechanism is the best suited for you and your application.

这篇关于如何在.net Core中使用RSA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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