• 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();
            }
  • 相关阅读:
    前后端分类状态下SpringSecurity的玩法
    拓展 centos 7
    linux 日志管理
    Linux 内存监控
    Linux 周期任务
    Linux 文件系统
    linux 磁盘管理
    图论 最短路总结
    进阶线段树之乘法操作
    暑假集训Day 10 小烈送菜
  • 原文地址:https://www.cnblogs.com/mycing/p/8277704.html
Copyright © 2020-2023  润新知