Qiniu.Util.Mac.SignRequest C# (CSharp) Method

SignRequest() public method

public SignRequest ( string url, byte reqBody ) : string
url string
reqBody byte
return string
        public string SignRequest(string url, byte[] reqBody)
        {
            Uri u = new Uri(url);
            using (HMACSHA1 hmac = new HMACSHA1(Encoding.UTF8.GetBytes(this.SecretKey)))
            {
                string pathAndQuery = u.PathAndQuery;
                byte[] pathAndQueryBytes = Encoding.UTF8.GetBytes(pathAndQuery);
                using (MemoryStream buffer = new MemoryStream())
                {
                    buffer.Write(pathAndQueryBytes, 0, pathAndQueryBytes.Length);
                    buffer.WriteByte((byte)'\n');
                    if (reqBody!=null && reqBody.Length > 0)
                    {
                        buffer.Write(reqBody, 0, reqBody.Length);
                    }
                    byte[] digest = hmac.ComputeHash(buffer.ToArray());
                    string digestBase64 = StringUtils.urlSafeBase64Encode(digest);
                    return string.Format("{0}:{1}", this.AccessKey, digestBase64);
                }
            }
        }

Usage Example

Exemplo n.º 1
0
 public static string createManageToken(string url, byte[] reqBody, Mac mac)
 {
     return(string.Format("QBox {0}", mac.SignRequest(url, reqBody)));
 }
All Usage Examples Of Qiniu.Util.Mac::SignRequest