APP使用腾讯云的短视频(点播)上传功能,为了安全性的考虑,需要服务端进行上传签名,然后再将签名内容返回给APP,用于APP端的视频上传
下面是官方提供的签名方法
public string GetUploadSignature() { string m_strSecId = "m_strSecId "; string m_strSecKey = "m_strSecKey "; int m_iRandom = new Random().Next(0, 1000000); long m_qwNowTime = GetTimeStamp(); int m_iSignValidDuration = 3600 * 24 * 2; string strContent = ""; strContent += ("secretId=" + Uri.EscapeDataString((m_strSecId))); strContent += ("¤tTimeStamp=" + m_qwNowTime); strContent += ("&expireTime=" + (m_qwNowTime + m_iSignValidDuration)); strContent += ("&random=" + m_iRandom); byte[] bytesSign = hash_hmac_byte(strContent, m_strSecKey); byte[] byteContent = System.Text.Encoding.Default.GetBytes(strContent); byte[] nCon = new byte[bytesSign.Length + byteContent.Length]; bytesSign.CopyTo(nCon, 0); byteContent.CopyTo(nCon, bytesSign.Length); return Convert.ToBase64String(nCon); }
其中hash_hmac_byte方法
private byte[] hash_hmac_byte(string signatureString, string secretKey) { var enc = Encoding.UTF8; HMACSHA1 hmac = new HMACSHA1(enc.GetBytes(secretKey)); hmac.Initialize(); byte[] buffer = enc.GetBytes(signatureString); return hmac.ComputeHash(buffer); }