[quote=引用 6 楼 sjyforg 的回复:] cookie加密。 如果对方能够搞到你本机的cookie,那你根本没什么秘密可言。
#region 加密&解密 /// <summary> /// DES对称加密方法 /// </summary> /// <param name="InitData">原始待加密数据</param> /// <param name="SecretKey">加密密钥</param> public static string EncryptData(object InitData, string SecretKey) { try { string newSecretKey = Utils.MD5(SecretKey + MySecretKey).Substring(16, 8); DESCryptoServiceProvider des = new DESCryptoServiceProvider(); //把字符串放到byte数组中 Byte[] inputByteArray = Encoding.Default.GetBytes(InitData.ToString()); //建立加密对象的密钥和偏移量 des.Key = ASCIIEncoding.ASCII.GetBytes(newSecretKey); //原文使用ASCIIEncoding.ASCII方法的GetBytes方法 des.IV = ASCIIEncoding.ASCII.GetBytes(newSecretKey); //使得输入密码必须输入英文文本 MemoryStream ms = new MemoryStream(); CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write); cs.Write(inputByteArray, 0, inputByteArray.Length); cs.FlushFinalBlock(); StringBuilder ret = new StringBuilder(); foreach (Byte b in ms.ToArray()) { ret.AppendFormat("{0:X2}", b); } ret.ToString(); return ret.ToString(); } catch { return ""; } } /// <summary> /// DES对称解密方法 /// </summary> /// <param name="EncryptedData">待解密数据</param> /// <param name="SecretKey">解密密钥</param> public static string DecryptData(object EncryptedData, string SecretKey) { try { string newSecretKey = Utils.MD5(SecretKey + MySecretKey).Substring(16, 8); string pToDecrypt = EncryptedData.ToString(); DESCryptoServiceProvider des = new DESCryptoServiceProvider(); Byte[] inputByteArray = new byte[pToDecrypt.Length / 2]; for (int x = 0; x < pToDecrypt.Length / 2; x++) { int i = (Convert.ToInt32(pToDecrypt.Substring(x * 2, 2), 16)); inputByteArray[x] = (byte)i; } //建立加密对象的密钥和偏移量,此值重要,不能修改 des.Key = ASCIIEncoding.ASCII.GetBytes(newSecretKey); des.IV = ASCIIEncoding.ASCII.GetBytes(newSecretKey); MemoryStream ms = new MemoryStream(); CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(), CryptoStreamMode.Write); cs.Write(inputByteArray, 0, inputByteArray.Length); cs.FlushFinalBlock(); return System.Text.Encoding.Default.GetString(ms.ToArray()); } catch { return ""; } } #endregion Utils.MD5(SecretKey + MySecretKey).Substring(16, 8); 这里的MD5自己写一个,然后随意截取其中8位,MySecretKey=内部密钥
cookie加密。 如果对方能够搞到你本机的cookie,那你根本没什么秘密可言。
保存cookie的时候加密 也就是cookie保存的是一段密文 别然看到也看不出来啥
62,041
社区成员
669,051
社区内容
加载中
.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。
希望和大家一起共同营造一个活跃、友好的社区氛围。
试试用AI创作助手写篇文章吧