如何在.net Core中使用RSA

编程入门 行业动态 更新时间:2024-10-23 04:38:01
本文介绍了如何在 Core中使用RSA的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我尝试使用 RSA 加密文件,但是它没有 toXmlString()和 fromXmlString 方法。如何在 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 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

本文发布于:2023-11-14 00:45:01,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1585755.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何在   net   RSA   Core

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!