Example DES Encrypt/Decrypt function in ASP.Net C# :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
protected byte[] EncryptKey = ASCIIEncoding.ASCII.GetBytes("ask_us_for_key"); public string DESEncrypt(string inString) { MemoryStream ms = new MemoryStream(); CryptoStream cs = new CryptoStream(ms, new DESCryptoServiceProvider().CreateEncryptor(EncryptKey, EncryptKey), CryptoStreamMode.Write); StreamWriter sw = new StreamWriter(cs); sw.Write(inString); sw.Flush(); cs.FlushFinalBlock(); sw.Flush(); return Convert.ToBase64String(ms.GetBuffer(), 0, (int)ms.Length); } public string DESDecrypt(string inString) { try { return new StreamReader(new CryptoStream(new MemoryStream( Convert.FromBase64String(inString)), new DESCryptoServiceProvider().CreateDecryptor(EncryptKey, EncryptKey), CryptoStreamMode.Read)).ReadToEnd(); } catch { } return ""; } |
Example MD5 function in ASP.Net C#:
1 2 3 4 5 6 7 8 9 10 |
public string BuildMD5(string inString) { byte[] hashed = MD5.Create().ComputeHash(Encoding.UTF8.GetBytes(inString)); StringBuilder sb = new StringBuilder(hashed.Length * 2); for (int i = 0; i < hashed.Length; i++) { sb.Append(hashed[i].ToString("x2")); } return sb.ToString(); } |