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;
}
}
}
}
Central美国独立日活动正在进行中,旗下美国达拉斯机房VPS 65折优惠,季付赠送双倍内存(需要发工单),Central租用的Hivelocity的机房,只支持信用卡和加密货币付款,不支持paypal,需要美国独服的可以谨慎入手试试。Central怎么样?Central便宜服务器,Central自称成立于2019年,主营美国达拉斯机房Linux vps、Windows vps、专用服务器和托管...
农历春节将至,腾讯云开启了热门爆款云产品首单特惠秒杀活动,上海/北京/广州1核2G云服务器首年仅38元起,上架了新的首单优惠活动,每天三场秒杀,长期有效,其中轻量应用服务器2G内存5M带宽仅需年费38元起,其他产品比如CDN流量包、短信包、MySQL、直播流量包、标准存储等等产品也参与活动,腾讯云官网已注册且完成实名认证的国内站用户均可参与。活动页面:https://cloud.tencent.c...
819云是我们的老熟人了,服务器一直都是稳定为主,老板人也很好,这次给大家带来了新活动,十分给力 香港CN2 日本CN2 物理机 E5 16G 1T 20M 3IP 240元0官方网站:https://www.819yun.com/ 特惠专员Q:442379204套餐介绍套餐CPU内存硬盘带宽IP价格香港CN2 (特价)E5 随机分配16G1T 机械20M3IP240元/月日本CN2 (...