我有以下在C#中生成HMACSHA1签名的代码片段。这是下面的代码
Encoding encoding = new UTF8Encoding();
HMACSHA1 hmac = new HMACSHA1(encoding.GetBytes(SecretKey.ToCharArray()));
StringBuilder data = new StringBuilder();
data.Append(Access);
data.Append(Id);
data.Append(Entity);
data.Append(Username);
string signature Convert.ToBase64String(hmac.ComputeHash(encoding.GetBytes(data.ToString().ToCharArray())));现在我想把它翻译成ruby,类似于:
Base64.encode64(OpenSSL::HMAC.hexdigest(OpenSSL::Digest::Digest.new('sha1'), secret_key, data)然而,对于相同的输入,结果是不相等的。它们在内部使用不同的散列算法吗?
谢谢
发布于 2014-02-07 06:58:03
根据响应中的建议,问题与编码有关,而不是在生成HMAC SHA1散列时使用原始字节。
https://stackoverflow.com/questions/21533053
复制相似问题