// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Data.Sql; using System.Data.SqlTypes; using System.Data.SqlClient; using System.Text; using System.Security.Cryptography; using Microsoft.SqlServer.Server; namespace E { public class Hash { private static readonly Encoding utf8 = new UTF8Encoding(); private static readonly MD5 md5 = new MD5CryptoServiceProvider(); [SqlFunction] public static SqlString MD5Calc(string s) { byte[] binres = md5.ComputeHash(utf8.GetBytes(s)); StringBuilder res = new StringBuilder(""); for(int i = 0; i < binres.Length; i++) { res.Append(String.Format("{0:x2}", binres[i])); } return res.ToString(); } } }