积极答复者
RSA加密每次密文不一样?

问题
-
string xmlPublicKey = "<RSAKeyValue><Modulus>uOMVRWVhMuGmnN7snAxmWmWb1cQejrExHlKnFcNxiXjx49nFRu7YCOovVCJBVNNa1g9b5BqU21KGBV7eArLmlTxGl1fzZU7KAG+HarctuBoCECVm7ViPVmAdfTSxo9hJco5uRVWECE4zB9JEA2c691E1jr3BLSyK5IfUS0/9a9k=</Modulus><Exponent>AQAB</Exponent></RSAKeyValue>";
string encodeStr = RSAEncrypt(xmlPublicKey, "password123");
Console.WriteLine(encodeStr);
////////RSA的加密函数 string
static public string RSAEncrypt(string xmlPublicKey, string m_strEncryptString)
{
byte[] PlainTextBArray;
byte[] CypherTextBArray;
string Result;
RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
rsa.FromXmlString(xmlPublicKey);
PlainTextBArray = (new UnicodeEncoding()).GetBytes(m_strEncryptString);
CypherTextBArray = rsa.Encrypt(PlainTextBArray, false);
Result = Convert.ToBase64String(CypherTextBArray);
return Result;
}同一个公钥,为什么每次加密后出来的密文都不一样呢?
答案
全部回复
-
Hi ,
将 CypherTextBArray = rsa.Encrypt(PlainTextBArray, false);
换成 CypherTextBArray = rsa.Encrypt(PlainTextBArray, true);就好了
Mike Feng
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.