公用靜態字串加密(字串來源)
{
MD5CryptoServiceProvider md = byte[] bytes = Encoding.UTF8.GetBytes(source);
byte[] 輸出 = md5.ComputeHash(bytes);
return BitConverter.ToString(output);
}
最常見的MD5加密,但不含解密。
DES加解密。
public class DES
{
private const string key = "av.6 {
DES/yptoServiceProvider des = new DESCryptoServiceProvider( Encoding.UTF8.GetBytes(source);
des.Key = ASCIIEncoding.ASCII.GetBytes(key Bytes(key);
MemoryStream ms = new MemoryStream();
cs = new CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write);
cs.W( bytes cs.FlushFinalBlock();
StringBuilder sb = new StringBuilder();
foreach (byte b in ms.ToArray())
AppendFormat("{0:X2 }", b);
}
公共 靜態 字串 解密(字串來源)
{
如果(資料====空|| source.Length == return source;
}
byte[] bytes = new byte[source.Length / 2];
for (int x = 0; x 位元組[x] = (位元組)我;
= ASCIIEncoding.ASCII.GetBytes(key);
des.IV = ASCIIEncoding.ASCII.GetBytes(key);
MemoryStream ms = new MemoryStream();
CryptoStream cs = new Cryp cs.Write(bytes, 0, bytes.Length);
cs.FlushFinalBlock();
return Encoding.UTF8.GetString(ms.ToArray());