我尝试使用以下代码加密和解密 cookie。我能够加密但解密功能接受字节输入。如何将 cookie 转换为字节以进行解密?错误是
无法将类型“System.Web.HttpCookie”隐式转换为“byte[]
错误行是“byte[] encrypted = myCookie;” 如何在解密之前将“cookie”转换为 byte[]?
Enryption:
HttpCookie myCookie = new HttpCookie("co");
myCookie.Values.Add("customerId", dr["customerId"].ToString());
using (AesCryptoServiceProvider myAes = new AesCryptoServiceProvider())
{
byte[] encrypted = AesEncryption.EncryptStringToBytes_Aes(myCookie.ToString(), myAes.Key, myAes.IV);
}
Response.Cookies.Add(myCookie);
Decription:
HttpCookie myCookie = Request.Cookies["co"];
byte[] encrypted = myCookie;
using (AesCryptoServiceProvider myAes = new AesCryptoServiceProvider())
{
string decripted = AesEncryption.DecryptStringFromBytes_Aes(myCookie.ToString(), myAes.Key, myAes.IV);
}