【发布时间】:2012-03-14 20:24:28
【问题描述】:
我在网上搜索了很多,但对 RSA 公钥和私钥加密持怀疑态度。
当我检查MSDN 网站时,我尝试了这个
RSACryptoServiceProvider rsaEncryptDecrypt = new RSACryptoServiceProvider();
byte[] privateKeyByte = rsaEncryptDecrypt.ExportParameters(true).Modulus;
byte[] publicKeyByte = rsaEncryptDecrypt.ExportParameters(false).Modulus;
string privateKey = Convert.ToBase64String(privateKeyByte);
string publicKey = Convert.ToBase64String(publicKeyByte);
字符串公钥和私钥相同!!! 这是正确的吗?我的意思是字符串怎么可能相同?不应该是两个不同的键吗?
如果我错了,请纠正我。我很困惑!
提前谢谢你!
更新
我弄错参数了,
但后来:当我看到
https://stackoverflow.com/questions/6592990/simple-rsa-encryption-decryption-in-net#answer-6593054"
如何获取字符串值?因为我必须将它存储在 App.config 中并随时访问它。我的意思是我需要将公钥和私钥都存储在 App.config 中
更新2
对不起,我刚刚使用了 RSACryptoServiceProvider 实例的 ToXmlString 属性。 得到了私钥和公钥。
【问题讨论】:
-
您刚刚转换了模数!两个键的那部分是相同的;) - 研究一下 RSA 并不难:你可以在这里阅读模数(N):en.wikipedia.org/wiki/RSA_%28algorithm%29#Key_generation
标签: c# rsa public-key private-key