Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Why does SHA256CryptoServiceProvider have host protection set while MD5CryptoServiceProvider does not
- namespace HashFunctions
- {
- using Microsoft.SqlServer.Server;
- using System;
- using System.Data.SqlTypes;
- using System.Security.Cryptography;
- using System.Text;
- public class CHash
- {
- [SqlFunction]
- public static SqlString Hash_MD5(SqlString inputString)
- {
- byte[] bytes = new UnicodeEncoding().GetBytes(Convert.ToString(inputString));
- byte[] buffer2 = new MD5CryptoServiceProvider().ComputeHash(bytes);
- return new SqlString(BitConverter.ToString(buffer2));
- }
- [SqlFunction]
- public static SqlString Hash_SHA256(SqlString inputString)
- {
- byte[] bytes = new UnicodeEncoding().GetBytes(Convert.ToString(inputString));
- byte[] buffer2 = new SHA256CryptoServiceProvider().ComputeHash(bytes);
- return new SqlString(BitConverter.ToString(buffer2)); // 2-character hex strings separated by dashes
- }
- } // class CHash
- } // namespace HashFunctions
Add Comment
Please, Sign In to add comment