問題描述
我想使用 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 公鑰/私鑰的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!