/******************************************************************************** ** 作者: 技术提供-刘晓勇 ** date: 2018/5/26 9:43:42 ** desc: 类文件所有功能代码均来自本人整理开发,完全开放共享 ** Ver.: V1.0.0 *********************************************************************************/ using System.IO; using System.Security.Cryptography; using System.Text; namespace SCP.AliYunCommon { public static class AliYunHmacSha1 { /// /// HMACSHA1 加密算法 /// /// 消息内容 /// 加密密钥 /// public static string HmacSha1Sign1(string message, string key) { var byteData = Encoding.UTF8.GetBytes(message); var byteKey = Encoding.UTF8.GetBytes(key); var hmac = new HMACSHA1(byteKey); var cs = new CryptoStream(Stream.Null, hmac, CryptoStreamMode.Write); cs.Write(byteData, 0, byteData.Length); cs.Close(); return ByteToHexStr(hmac.Hash); } /// /// byte 转为16进制 /// /// 需要转换的byte[] /// public static string ByteToHexStr(byte[] bytes) { var returnStr = ""; if (bytes != null) { foreach (var t in bytes) { returnStr += t.ToString("X2"); } } return returnStr.ToLower(); } } }