• C# HmacSha512 与 java HmacSha512 加密


    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();
            }
  • 相关阅读:
    Shiro安全框架之集成 Web(下)
    Shiro安全框架之集成 Web(中)
    Shiro安全框架之集成 Web(上)
    01背包
    巴什博弈
    斐波那契博弈
    一. 至少转最多
    平面分割类问题
    求凸包(安德鲁算法)
    GCD和exGCD
  • 原文地址:https://www.cnblogs.com/mycing/p/8277704.html
Copyright © 2020-2023  润新知