C# equivalent to hash_hmac in PHP

前端 未结 3 1029
盖世英雄少女心
盖世英雄少女心 2020-12-01 06:38

using .NET and C# i need to provide an integrity string using HMAC SHA512 to a PHP server . Using in C# :

Encoding encoding = Encoding.UTF8;
byte[] keyByte          


        
3条回答
  •  青春惊慌失措
    2020-12-01 07:00

        private static string HashHmac(string message, string secret)
        {
            Encoding encoding = Encoding.UTF8;
            using (HMACSHA512 hmac = new HMACSHA512(encoding.GetBytes(secret)))
            {
                var msg = encoding.GetBytes(message);
                var hash = hmac.ComputeHash(msg);
                return BitConverter.ToString(hash).ToLower().Replace("-", string.Empty);
            }
        }
    

提交回复
热议问题