asp.net 對中文漢字的加密與解密代碼
更新時間:2009年05月08日 22:44:39 作者:
一般的加密方法,解密比較復(fù)雜,所有大家看可以嘗試用下面的代碼。
復(fù)制代碼 代碼如下:
protected void Page_Load(object sender, EventArgs e)
{
//加密算法
string username = "我是陳建勇";
//MD5加密 - 得到32位加密數(shù)據(jù),數(shù)據(jù)不好解密。過于復(fù)雜。
username =FormsAuthentication.HashPasswordForStoringInConfigFile(username, "MD5");
//SHA1加密 - 得到40位加密數(shù)據(jù),數(shù)據(jù)不好解密。過于復(fù)雜。
string username1 = FormsAuthentication.HashPasswordForStoringInConfigFile(username, "SHA1");
Response.Write(username+"<br>");
Response.Write(username1+"<br>");
//解密算法
//普通加密
string s = "我是陳建勇";
string encodestr = "";
byte[] bytes = System.Text.Encoding.GetEncoding(0).GetBytes(s);
try
{
encodestr = Convert.ToBase64String(bytes);
Response.Write("aa");
}
catch
{
encodestr = s;
Response.Write("bb");
}
Response.Write(encodestr+"<br>");
//普通解密
string decodestr = "";
byte[] bytes1 = Convert.FromBase64String(encodestr);
try
{
decodestr = System.Text.Encoding.GetEncoding(0).GetString(bytes1);
Response.Write("cc");
}
catch
{
Response.Write("dd");
decodestr = encodestr;
}
Response.Write(decodestr+"<br>");
//普通加密
string myname = "陳建勇";
myname = System.Web.HttpUtility.UrlEncode(myname, System.Text.Encoding.UTF8);
Response.Write(myname+"<br>");
//普通解密
myname = System.Web.HttpUtility.UrlDecode(myname, System.Text.Encoding.UTF8);
Response.Write(myname);
}
相關(guān)文章
asp.net 點縮略圖彈出隨圖片大小自動調(diào)整的頁面
程序用asp.net編寫,功能主要是,點pic_small.Aspx頁面的縮略圖后彈出pic_all.aspx頁面,pic_all.aspx頁面的大小要根據(jù)圖片大小自動調(diào)整2009-06-06
asp.net uploadify實現(xiàn)多附件上傳功能
這篇文章主要為大家詳細(xì)介紹了asp.net uploadify實現(xiàn)多附件上傳功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-11-11
讓Silverlight 2.0動畫動起來Making Silverlight 2.0 animation Start(
Microsoft Expression Blend 2 制作動畫個人感覺倒像3DMAX 可以自動捕捉關(guān)鍵幀2008-11-11
AntDesign Pro + .NET Core 實現(xiàn)基于JWT的登錄認(rèn)證功能
這篇文章主要介紹了AntDesign Pro + .NET Core 實現(xiàn)基于JWT的登錄認(rèn)證功能,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2021-03-03
ASP.net如何連接SQL SERVER 2012數(shù)據(jù)庫
這篇文章主要介紹了ASP.net連接SQL SERVER 2012數(shù)據(jù)庫的方法,非常不錯,在項目開發(fā)中經(jīng)常可以用到,需要的朋友可以參考下2016-08-08
不使用web服務(wù)(Service)實現(xiàn)文本框自動完成擴展
以前寫Ajax 的AutoCompleteExtender功能,都需要寫WCF Service或是Web Service數(shù)據(jù)源,下面的演示,不用寫Service來實現(xiàn)文本框的AutoCompete extender功能,感興趣的朋友可以參考下哈2013-04-04

