問題描述
我想使用 RSA 公鑰加密.存儲或檢索私鑰和公鑰的最佳方式是什么?XML 在這里是個(gè)好主意嗎?
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);
因?yàn)?RSAParameters 有以下成員:D, DP, DQ, Exponent, InverseQ, Modulus, P, Q
Because RSAParameters have the following members: D, DP, DQ, Exponent, InverseQ, Modulus, P, Q
哪一個(gè)是關(guān)鍵?
推薦答案
我成功的是將密鑰存儲為 XML.RSACryptoServiceProvider 中有兩種方法:ToXmlString 和 FromXmlString.ToXmlString 將返回一個(gè) XML 字符串,該字符串要么僅包含公鑰數(shù)據(jù),要么包含公鑰和私鑰數(shù)據(jù),具體取決于您設(shè)置其參數(shù)的方式.當(dāng)提供僅包含公鑰數(shù)據(jù)或同時(shí)包含公鑰和私鑰數(shù)據(jù)的 XML 字符串時(shí),F(xiàn)romXmlString 方法將使用適當(dāng)?shù)拿荑€數(shù)據(jù)填充 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.
這篇關(guān)于如何存儲/檢索 RSA 公鑰/私鑰的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!