Advertisement
gunnercrakr

Encryption procedures

Nov 23rd, 2019
3,276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ASP 0.82 KB | None | 0 0
  1. protected byte[] EncryptKey = ASCIIEncoding.ASCII.GetBytes("ask_us_for_key");
  2. public string DESEncrypt(string inString)
  3. {
  4.     MemoryStream ms = new MemoryStream();
  5.     CryptoStream cs = new CryptoStream(ms, new DESCryptoServiceProvider().CreateEncryptor(EncryptKey, EncryptKey), CryptoStreamMode.Write);
  6.     StreamWriter sw = new StreamWriter(cs);
  7.     sw.Write(inString);
  8.     sw.Flush();
  9.     cs.FlushFinalBlock();
  10.     sw.Flush();
  11.     return Convert.ToBase64String(ms.GetBuffer(), 0, (int)ms.Length);
  12. }
  13. public string DESDecrypt(string inString)
  14. {
  15.     try
  16.     {
  17.         return new StreamReader(new CryptoStream(new MemoryStream( Convert.FromBase64String(inString)), new DESCryptoServiceProvider().CreateDecryptor(EncryptKey, EncryptKey), CryptoStreamMode.Read)).ReadToEnd();
  18.     }
  19.     catch
  20.     {
  21.     }
  22.     return "";
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement