使用反斜杠字符时,HMAC SHA256不会生成预期的哈希爪2.2.2 [英] HMAC SHA256 does not generate the expected Hash Paw 2.2.2 when backslash character is used

查看:207
本文介绍了使用反斜杠字符时,HMAC SHA256不会生成预期的哈希爪2.2.2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在测试Paw应用程序,它很棒.开发人员做了出色的工作,似乎他真的很喜欢他的应用程序.

我发现,当Input包含反斜杠字符或使用"\ n"(不带引号)的组合时,HMAC Sha256 Crypto函数不会返回预期的哈希值.

示例:

输入:GET\n/test/api

键:BE8B3551-1892-4544-9FDC-EC0B2C8608F8

结果: f9VF6Sy0oq645lKRcXF3N96aPZLy8qhwrbJconOJhEI=

预期: VciY9BUCzL3KUUvFtmcRSuP2N5IkQ2gLvjjYgd3T9Uc=

我正在使用基于CryptoJS脚本的下一个javascript代码为正在测试的API生成正确的哈希值:

 <script src="http://crypto-js.googlecode.com/svn/tags/3.0.2/build/rollups/hmac-sha256.js"></script>
<script src="http://crypto-js.googlecode.com/svn/tags/3.0.2/build/components/enc-base64-min.js"></script>

<script>
    var message = 'GET\n/test/api';
var key = 'BE8B3551-1892-4544-9FDC-EC0B2C8608F8';
  var hash = CryptoJS.HmacSHA256(message, key);
  var hashInBase64 = CryptoJS.enc.Base64.stringify(hash);
document.write(hashInBase64);
</script> 

 <script src="http://crypto-js.googlecode.com/svn/tags/3.0.2/build/components/enc-base64-min.js"></script>
<script src="http://crypto-js.googlecode.com/svn/tags/3.0.2/build/rollups/hmac-sha256.js" ></script> 

解决方案

此处的问题是Paw解释您的\n字符串实际上包含字符\,后跟字符n,而不是换行符./p>

您可以做的是通过按Option/Alt + Enter插入实际的换行符. (该字段会出现视觉故障,您一次只能看到一行,但结果是正确的)

i'm testing the Paw app, it is awesome. The developer did an outstanding work, it seems that he truly loves his app.

I found that the HMAC Sha256 Crypto function doesn't returns the expected hash when the Input includes a backslash character or combinations that uses it "\n" (without quotes).

Example:

input: GET\n/test/api

key: BE8B3551-1892-4544-9FDC-EC0B2C8608F8

Result: f9VF6Sy0oq645lKRcXF3N96aPZLy8qhwrbJconOJhEI=

Expected: VciY9BUCzL3KUUvFtmcRSuP2N5IkQ2gLvjjYgd3T9Uc=

I'm generating the correct hash for the API that i'm testing using the next javascript code, which is based in the CryptoJS script:

<script src="http://crypto-js.googlecode.com/svn/tags/3.0.2/build/rollups/hmac-sha256.js"></script>
<script src="http://crypto-js.googlecode.com/svn/tags/3.0.2/build/components/enc-base64-min.js"></script>

<script>
    var message = 'GET\n/test/api';
var key = 'BE8B3551-1892-4544-9FDC-EC0B2C8608F8';
  var hash = CryptoJS.HmacSHA256(message, key);
  var hashInBase64 = CryptoJS.enc.Base64.stringify(hash);
document.write(hashInBase64);
</script>

<script src="http://crypto-js.googlecode.com/svn/tags/3.0.2/build/components/enc-base64-min.js"></script>
<script src="http://crypto-js.googlecode.com/svn/tags/3.0.2/build/rollups/hmac-sha256.js" ></script>

解决方案

The issue here is that Paw interprets your \n string has actually the character \ followed by the character n and not a newline character.

What you can do is to insert an actual newline by pressing Option/Alt + Enter. (The field will have a visual glitch, and you'll only be able to see one line at a time, but the result will be correct)

这篇关于使用反斜杠字符时,HMAC SHA256不会生成预期的哈希爪2.2.2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆