MD5加密解密

2021-09-06 10:39:48 字數 2776 閱讀 3324

方法一

首先,先簡單介紹一下md5

md5的全稱是message-digest algorithm 5(資訊-摘要演算法,在90年代初由mit laboratory for computer science和rsa data security inc的ronald l. rivest開發出來, 經md2、md3和md4發展而來。

md5具有很好的安全性(因為它具有不可逆的特徵,加過密的密文經過解密後和加密前的東東相同的可能性極小)

引用using system.security.cryptography;

using system.text;

具體**如下(寫在按鈕的click事件裡):

byte result = encoding.default.getbytes(this.tbpass.text.trim());    //tbpass為輸入密碼的文字框

md5 md5 = new md5cryptoserviceprovider();

byte output = md5.computehash(result);

this.tbmd5pass.text = bitconverter.tostring(output).replace("-","");  //tbmd5pass為輸出加密文字的文字框

方法二c# md5加密(上)

string a; //加密前資料

string b; //加密後資料

b=system.web.security.formsauthentication.hashpasswordforstoringinconfigfile(a,"md5")

using   system;

using   system.security.cryptography;

方法2public   static   string   ge***5(string   mystring)  

using   system.security.cryptography;

///  

///   給乙個字串進行md5加密

///  

///   待加密字串

///   加密後的字串

public   static   string   md5encrypt(string   strtext)

c# md5加密

using system.security.cryptography;

private void btnok_click(object sender, system.eventargs e)

else if(texpassword.text.trim()=="")

else

else

}else

}catch(exception exec)

finally}}

方法三c# md5加密

c#開發筆記 

一、c# md5-16位加密例項,32位加密例項(兩種方法)

環境:vs.net2005/sql server2000/xp測試通過

1.md5 16位加密例項

using system;

using system.collections.generic;

using system.text;

using system.security.cryptography;

namespace md5

/**

/// md5 16位加密 加密後密碼為大寫

///

///

///

public static string ge***5str(string convertstring)

/**

/// md5 16位加密 加密後密碼為小寫

///

///

///

public static string ge***5str(string convertstring)

/**

/// md5 32位加密

///

///

///

static  string usermd5(string str)

return pwd;}}

}using system.security.cryptography;

using system.text;

二、首先在介面中引入:using system.web.security;

假設密碼對話方塊名字password,對輸入的密碼加密後存入變數pwd中,語句如下:

string pwd = formsauthentication.hashpasswordforstoringinconfigfile(password.text, "md5");

如果要錄入則錄入pwd,這樣資料庫實際的密碼為202*****等亂碼了。

如果登入查詢則要:

select username,password from users where username='"+ username.text +"' and password='"+ pwd +"'

因為md5不能解密,只能把原始密碼加密後與資料庫中加密的密碼比較

三、c# md5 加密方法 16位或32位

public string md5(string str,int code)

else//32位加密   }

public static string stringtomd5(string str, int i)

else if (i == 32 && str != string.empty)

else}}

MD5加密解密

using system using system.text using system.io using system.security.cryptography class class1 txtkey txtiv kl7zgtm1dvq 設定加密iv btnivgen console.writel...

MD5加密解密

using system using system.text using system.io using system.security.cryptography class class1 txtkey txtiv kl7zgtm1dvq 設定加密iv btnivgen console.writel...

MD5加密解密

protected void page load object sender,eventargs e s0 console.writeline 加密 s1 console.writeline 解密 s2 md5解密 public string md5decrypt string ptodecrypt...