asp.net实现MD5加密的方法asp.net自带的md5加密用下面这种方法但这种方法只能加密不能解密。
Respo nse.Write (Forms Authe ntica tion.HashP asswo rdFor Stori ngInC onfig Fi le("要加密的字符串","MD5"));
下面是使用密钥的加密带解密的代码
代码
/*用法protected void Page_Load(object sender, EventArgs e)
{
//加密this.Title=CEncrypt.DesEncrypt("pwd",CEncrypt.Key);this.Title+=CEncrypt.DesDecrypt(this.Title,CEncrypt.Key);
Response.Write(CEncrypt.DesDecrypt("gAYyhdLQunc=",CEncrypt.Key));
}
*/using Syste m;using Syste m. IO;using Syste m.Text;using Syste m.Security.Cryptography;using Syste m.Web;namespaceYD.Common
{
///<summa ry>
///加密码类
///</summa ry>publ icclass CEncrypt
{
///<summa ry>
///加密
///</summa ry>
///<param name="inputString"></param>
///<returns></returns>publ ic static string DesEncrypt(string inputString)
{return DesEncrypt(inputString,Key);
}
///<summa ry>
///解密
///</summa ry>
///<param name="inputString"></param>
///<returns></returns>publ ic static string DesDecrypt(string inputString)
{
return DesDecrypt(inputString,Key);
}
///<summa ry>
///密匙
///</summa ry>private static string Key
{get
{return"hongye10";
}
}
///<summary>
///加密字符串
///注意:密钥必须为 位
///</summa ry>
///<param name="strTe xt">字符串</param>
///<param name="encry ptKey">密钥</param>
///<param name="encry ptKey">返回加密后的字符串</param>publ i c static string DesEncrypt(string inputString, string encryptKey)
{byte[]byKey=nul l;byte[] IV={0x12,0x34,0x56,0x78,0x90,0xAB,0xCD,0xEF};try
{byKey=Syste m.Text.Encoding.UTF8.GetBytes(encryptKey.Subst ring(0,8));
DESCryptoServiceProvider des= new DESCryptoServiceProvider();byte[] inputByteArray=Encoding.UTF8.GetBytes(inputString);
MemoryStream ms= new MemoryStream();
CryptoStream cs = new Crypt oStream(ms, des.CreateEncryptor(byKey, IV),CryptoStreamMode.Write);cs.Write(input ByteArray,0, inputByteArray.Length);cs.FlushFinalBlock();return Convert.ToBase64String(ms.ToArray());
}catch(System.Exception error)
{
//return error.Message;returnnul l;
}
}
///<summa ry>
///解密字符串
///</summa ry>
///<param name="this. input Strin g">加了密的字符串</param>
///<param name="decry ptKey">密钥</param>
///<param name="decry ptKey">返回解密后的字符串</param>publ ic static string DesDecrypt(string inputString, string decryptKey)
{byte[]byKey=nul l;byte[] IV={0x12,0x34,0x56,0x78,0x90,0xAB,0xCD,0xEF};byte[] inputByteArray=new Byte[inputString.Length];try
{byKey=Syste m.Text.Encoding.UTF8.GetBytes(decryptKey.Subst ring(0,8));
DESCryptoServiceProvider des= new DESCryptoServiceProvider();inputByteArray=Convert.FromBase64String(inputString);
MemoryStream ms= new MemoryStream();
CryptoStream cs = new Crypt oStream(ms, des.CreateDecryptor(byKey, IV),CryptoStreamMode.Write);cs.Write(inputByteArray,0, inputByteArray.Length);cs.FlushFinalBlock();
System.Text.Encoding encoding=new System.Text.UTF8Encoding();return encoding.GetString(ms.ToArray());
}catch(System.Exception error)
{
//return error.Message;returnnul l;
}
}
}
}
DogYun怎么样?DogYun是一家2019年成立的国人主机商,称为狗云,提供VPS及独立服务器租用,其中VPS分为经典云和动态云(支持小时计费及随时可删除),DogYun云服务器基于Kernel-based Virtual Machine(Kvm)硬件的完全虚拟化架构,您可以在弹性云中,随时调整CPU,内存,硬盘,网络,IPv4路线(如果该数据中心接入了多条路线)等。DogYun弹性云服务器优...
Hosteons,一家海外主机商成立于2018年,在之前还没有介绍和接触这个主机商,今天是有在LEB上看到有官方发送的活动主要是针对LEB的用户提供的洛杉矶、达拉斯和纽约三个机房的方案,最低年付21美元,其特点主要在于可以从1G带宽升级至10G,而且是免费的,是不是很吸引人?本来这次活动是仅仅在LEB留言提交账单ID才可以,这个感觉有点麻烦。不过看到老龚同学有拿到识别优惠码,于是就一并来分享给有需...
pigyun怎么样?PIGYun成立于2019年,2021是PIGYun为用户提供稳定服务的第三年,期待我们携手共进、互利共赢。PIGYun为您提供:香港CN2线路、韩国CN2线路、美西CUVIP-9929线路优质IaaS服务。月付另有通用循环优惠码:PIGYun,获取8折循环优惠(永久有效)。目前,PIGYun提供的香港cn2云服务器仅29元/月起;韩国cn2云服务器仅22元/月起;美国CUVI...