加密MD5加密解密方法

md5解密  时间:2021-01-31  阅读:()

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;

}

}

}

}

DogYun27.5元/月香港/韩国/日本/美国云服务器,弹性云主机

DogYun怎么样?DogYun是一家2019年成立的国人主机商,称为狗云,提供VPS及独立服务器租用,其中VPS分为经典云和动态云(支持小时计费及随时可删除),DogYun云服务器基于Kernel-based Virtual Machine(Kvm)硬件的完全虚拟化架构,您可以在弹性云中,随时调整CPU,内存,硬盘,网络,IPv4路线(如果该数据中心接入了多条路线)等。DogYun弹性云服务器优...

A400互联37.8元/季,香港节点cn2,cmi线路云服务器,1核/1G/10M/300G

A400互联怎么样?A400互联是一家成立于2020年的商家,A400互联是云服务器网(yuntue.com)首次发布的云主机商家。本次A400互联给大家带来的是,全新上线的香港节点,cmi+cn2线路,全场香港产品7折优惠,优惠码0711,A400互联,只为给你提供更快,更稳,更实惠的套餐,香港节点上线cn2+cmi线路云服务器,37.8元/季/1H/1G/10M/300G,云上日子,你我共享。...

Kinponet是谁?Kinponet前身公司叫金宝idc 成立于2013年 开始代理销售美国vps。

在2014年发现原来使用VPS的客户需求慢慢的在改版,VPS已经不能满足客户的需求。我们开始代理机房的独立服务器,主推和HS机房的独立服务器。经过一年多的发展,我们发现代理的服务器配置参差不齐,机房的售后服务也无法完全跟上,导致了很多问题发生,对使用体验带来了很多的不便,很多客户离开了我们。经过我们慎重的考虑和客户的建议。我们在2015开始了重大的改变, 2015年,我们开始计划托管自己...

md5解密为你推荐
电脑杀毒软件哪个好电脑杀毒用哪个好?莫代尔和纯棉哪个好莫代尔和纯棉的区别,莫代尔和纯棉哪个好朱祁钰和朱祁镇哪个好朱高炽在位时间长还是朱祁钰在位时间长?音乐播放器哪个好目前音质最好的音乐播放器核芯显卡与独立显卡哪个好核芯显卡与独立显卡哪个好尼康和佳能单反哪个好尼康和佳能哪个好尼康和佳能单反哪个好佳能和尼康哪个好雅思和托福哪个好考雅思和托福哪个好考一点行车记录仪哪个好行车记录仪什么牌子好360云盘关闭360云盘,关闭了吗,还能用吗,推荐一个其他云盘
1g虚拟主机 厦门虚拟主机 域名停靠 紧急升级请记住新域名 长春域名注册 idc评测 唯品秀 ddos 服务器评测 hostgator stablehost blackfriday sugarsync 国外服务器网站 godaddy续费优惠码 青果网 中国特价网 申请个人网页 发包服务器 亚洲小于500m 更多