using System; using System.Data; using System.Data.SqlClient; using System.Data.SqlTypes; using Microsoft.SqlServer.Server; using System.Security.Cryptography; using System.Text;
public partial class UserDefinedFunctions { [Microsoft.SqlServer.Server.SqlFunction]
/// <summary> /// md5加密 /// </summary> /// <param name="text"></param> public static SqlString MD5Encrypt(SqlString text) { string hash = string.Empty; MD5CryptoServiceProvider md5provider = new MD5CryptoServiceProvider(); byte[] bytes = md5provider.ComputeHash(new UTF8Encoding().GetBytes(text.ToString())); for (int i = 0; i < bytes.Length; i++) { hash += bytes[i].ToString("x2"); } return new SqlString(hash.ToString()); }
/// <summary> /// 字符串转guid /// </summary> /// <param name="text"></param> /// <returns></returns> public static SqlString Guid(SqlString text) { Guid guid = new Guid(text.ToString()); return new SqlString(guid.ToString()); }