我尝试使用 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
发布评论