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;
}
}
}
}
HostHatch在当地时间7月30日发布了一系列的促销套餐,涉及亚洲和欧美的多个地区机房,最低年付15美元起,一次买2年还能免费升级双倍资源。商家成立于2011年,提供基于KVM架构的VPS主机,数据中心包括中国香港、美国、英国、荷兰、印度、挪威、澳大利亚等国家的十几个地区机房。官方网站:https://hosthatch.com/NVMe VPS(香港/悉尼)1 CPU core (12.5%...
Vinahost,这个主机商还是第一次介绍到,翻看商家的介绍信息,是一家成立于2008年的老牌越南主机商,业务涵盖网站设计、域名、SSL证书、电子邮箱、虚拟主机、越南VPS、云计算、越南服务器出租以及设备托管等,机房主要在越南胡志明市的Viettle和VNPT数据中心,其中VNPT数据中心对于国内是三网直连,速度优。类似很多海外主机商一样,希望拓展自己的业务,必须要降价优惠或者增加机房迎合需求用户...
香港站群多ip服务器多少钱?想做好站群的SEO优化,最好给每个网站都分配一个独立IP,这样每个网站之间才不会受到影响。对做站群的站长来说,租用一家性价比高且提供多IP的香港多ip站群服务器很有必要。零途云推出的香港多ip站群云服务器多达256个IP,可以满足站群的优化需求,而且性价比非常高。那么,香港多ip站群云服务器价格多少钱一个月?选择什么样的香港多IP站群云服务器比较好呢?今天,小编带大家一...