Advertisement
javitolin

Untitled

Mar 28th, 2015
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. using System.Security.Cryptography;
  2.  
  3.  
  4.  
  5. public string encrypt(string InputText)
  6. {
  7. byte[] clearData = System.Text.Encoding.UTF8.GetBytes(InputText);
  8. MemoryStream ms = new MemoryStream();
  9. CryptoStream cs = new CryptoStream(ms, this.tDes.CreateEncryptor(), CryptoStreamMode.Write);
  10. cs.Write(clearData, 0, clearData.Length);
  11. cs.FlushFinalBlock();
  12. byte[] CipherBytes = ms.ToArray();
  13. ms.Close();
  14. cs.Close();
  15. string EncryptedData = Convert.ToBase64String(CipherBytes);
  16. return EncryptedData;
  17. }
  18.  
  19. /// <summary>
  20. /// Decrypt the specified CipherText.
  21. /// </summary>
  22. /// <param name="CipherText">Cipher text.</param>
  23. public string decrypt(string CipherText)
  24. {
  25. //return CipherText;
  26. //Console.WriteLine ("dec {0}",CipherText);
  27. //byte[] cipherData = System.Text.Encoding.UTF8.GetBytes(CipherText);
  28. byte[] decriptedData = Convert.FromBase64String(CipherText);
  29. MemoryStream ms = new MemoryStream();
  30. CryptoStream cs = new CryptoStream(ms, this.tDes.CreateDecryptor(), CryptoStreamMode.Write);
  31. cs.Write(decriptedData, 0, decriptedData.Length);
  32. cs.FlushFinalBlock();
  33. byte[] ClearBytes = ms.ToArray();
  34. ms.Close();
  35. cs.Close();
  36. return System.Text.Encoding.UTF8.GetString (ClearBytes);
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement