62,046
社区成员
发帖
与我相关
我的任务
分享
//加密算法
public string EnCodes(string text)
{
RSACryptoServiceProvider rsa1 = new RSACryptoServiceProvider();
RSACryptoServiceProvider rsa2 = new RSACryptoServiceProvider();
string publicKey = rsa1.ToXmlString(true);
HttpContext.Current.Response.Cookies["PublicKey"].Value = publicKey;
rsa2.FromXmlString(publicKey);
byte[] ECode = rsa2.Encrypt(System.Text.Encoding.UTF8.GetBytes(text),false);
return Convert.ToBase64String(ECode);
}
//解密算法
public string DeCodes(string text)
{
RSACryptoServiceProvider rsa1 = new RSACryptoServiceProvider();
byte[] DCode = Convert.FromBase64String(text);
string publicKey = HttpContext.Current.Request.Cookies["PublicKey"].Value.ToString();
rsa1.FromXmlString(publicKey);
byte[] DCode2 = rsa1.Decrypt(DCode,false);
return System.Text.Encoding.UTF8.GetString(DCode2);
}