Guest User

Untitled

a guest
Aug 19th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. Why does SHA256CryptoServiceProvider have host protection set while MD5CryptoServiceProvider does not
  2. namespace HashFunctions
  3. {
  4. using Microsoft.SqlServer.Server;
  5. using System;
  6. using System.Data.SqlTypes;
  7. using System.Security.Cryptography;
  8. using System.Text;
  9.  
  10. public class CHash
  11. {
  12. [SqlFunction]
  13. public static SqlString Hash_MD5(SqlString inputString)
  14. {
  15. byte[] bytes = new UnicodeEncoding().GetBytes(Convert.ToString(inputString));
  16. byte[] buffer2 = new MD5CryptoServiceProvider().ComputeHash(bytes);
  17.  
  18. return new SqlString(BitConverter.ToString(buffer2));
  19. }
  20.  
  21. [SqlFunction]
  22. public static SqlString Hash_SHA256(SqlString inputString)
  23. {
  24. byte[] bytes = new UnicodeEncoding().GetBytes(Convert.ToString(inputString));
  25. byte[] buffer2 = new SHA256CryptoServiceProvider().ComputeHash(bytes);
  26.  
  27. return new SqlString(BitConverter.ToString(buffer2)); // 2-character hex strings separated by dashes
  28. }
  29.  
  30. } // class CHash
  31.  
  32. } // namespace HashFunctions
Add Comment
Please, Sign In to add comment