MD5,加密解密

2021-06-28 21:28:16 字數 959 閱讀 1454

在工作中有時會用到把密碼md5加密後放入資料庫的情況,

咱們現在就來說說如何md5加密。

先說說**,

public static string string2md5(string instr)catch (exception e)  

char chararray = instr.tochararray();  

byte bytearray = new byte[chararray.length];  

//問題一如果加密的字串是個帶漢字的佔兩個位元組

,此時成char轉成byte 必定要溢位掉一些資料,

但是經過測試,字串也可再解密成原來的漢字

for (int i = 0; i < chararray.length; i++)  

bytearray[i] = (byte) chararray[i];  

byte md5bytes = md5.digest(bytearray);  

stringbuffer hexvalue = new stringbuffer();  

for (int i = 0; i < md5bytes.length; i++)  

string s = new string(a);  

return s;  

}//測試

public static void main(string args)   

再介紹下原碼,反碼,補碼知識。

1>補碼的設計目的是:

⑴ 使符號位能與有效值部分一起參加運算,從而簡化運算規則。補碼機器數中的符號位,並不是強加上去的,是資料本身的自然組成部分,可以正常地參與運算。

⑵ 使減法運算轉換為加法運算,進一步簡化計算機中運算器的線路設計。

2>反碼是原碼與補碼轉換的乙個中間過渡,使用較少。

3>所有這些轉換都是在計算機的最底層進行的,而在我們使用的彙編、c等其他高階語言中使用的都是原碼。

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...