using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Security.Cryptography; using System.Windows.Forms; namespace PTMedicalInsurance.Common { class Encrypt { public static string ToBase64hmac(string strText, string strKey) { HMACSHA1 myHMACSHA1 = new HMACSHA1(Encoding.UTF8.GetBytes(strKey)); byte[] byteText = myHMACSHA1.ComputeHash(Encoding.UTF8.GetBytes(strText)); return System.Convert.ToBase64String(byteText); } public static string HMACSHA1Text(string EncryptText, string EncryptKey) { //HMACSHA1加密 string message; string key; message = EncryptText; key = EncryptKey; System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding(); byte[] keyByte = encoding.GetBytes(key); HMACSHA1 hmacsha1 = new HMACSHA1(keyByte); byte[] messageBytes = encoding.GetBytes(message); byte[] hashmessage = hmacsha1.ComputeHash(messageBytes); //return ByteToString(hashmessage); return Convert.ToBase64String(hashmessage); } public static string HMACSHA1Text2(string EncryptText, string EncryptKey) { //HMACSHA1加密 HMACSHA1 hmacsha1 = new HMACSHA1(); hmacsha1.Key = System.Text.Encoding.UTF8.GetBytes(EncryptKey); byte[] dataBuffer = System.Text.Encoding.UTF8.GetBytes(EncryptText); byte[] hashBytes = hmacsha1.ComputeHash(dataBuffer); return Convert.ToBase64String(hashBytes); } } }