1. 程式人生 > >C# HmacSha512 與 java HmacSha512 加密

C# HmacSha512 與 java HmacSha512 加密

replace query generator arr .get ray oba secretkey lower

C# HmacSha512 與 java HmacSha512 加密。

 /// <summary>
        /// HmacSha512 加密
        /// </summary>
        /// <param name="clearMessage"></param>
        /// <param name="secretKeyString"></param>
        /// <returns></returns>
        protected string HmacSha512(string
clearMessage, string secretKeyString) { Encoding encoder = Encoding.UTF8; //Transform the clear query string to a byte array byte[] messageBytes = encoder.GetBytes(clearMessage); //Transform the secret key string to a byte array var key = Convert.ToBase64String(encoder.GetBytes(secretKeyString));
byte[] secretKeyBytes = encoder.GetBytes(key); //Init the Hmac SHA512 generator with the key HMACSHA512 hmacsha512 = new HMACSHA512(secretKeyBytes); //Hash the message byte[] hashValue = hmacsha512.ComputeHash(messageBytes); //Transform the hash bytes array to a string string
string hmac = BitConverter.ToString(hashValue).Replace("-", ""); //Force the case of the HMAC key to Uppercase return hmac.ToLower(); }

C# HmacSha512 與 java HmacSha512 加密