Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your problem is that you've got the wrong test vector. Your key:</p> <blockquote> <p>000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f</p> </blockquote> <p>and your message "<code>Sample #1</code>" are from <strong>Example A.1: SHA-1 with 64-Byte Key</strong> in <a href="http://csrc.nist.gov/publications/fips/fips198/fips-198a.pdf" rel="nofollow">FIPS 198a</a>, whereas your expected output:</p> <blockquote> <p>74766e5f6913e8cb6f7f108a11298b15010c353a</p> </blockquote> <p>is from <strong>Example A.2: SHA-1 with 20-Byte Key</strong>. The correct first-stage hash output for Example A.1 is:</p> <blockquote> <p>bcc2c68cabbbf1c3f5b05d8e7e73a4d27b7e1b20</p> </blockquote> <p>Also note that NIST has published a newer, somewhat more comprehensive set of <a href="http://csrc.nist.gov/groups/ST/toolkit/examples.html#aMsgAuth" rel="nofollow">test vectors for HMAC-SHA-1 and HMAC-SHA-2</a>.</p> <hr> <p>OK, I found the second problem. Peeking at the source code of <code>$u.sha1()</code>, that function starts with:</p> <pre><code>var msg = internal.utf8EncodeToCharCodeArray(str) </code></pre> <p>That is, it expects its input to be a Unicode string, and converts it into an octet string using the UTF-8 encoding before hashing it. In particular, this means that characters with codepoints above 127 are converted into multiple bytes.</p> <p>Unfortunately, the HMAC construction operates on raw octet strings, not on Unicode strings. Worse yet, there doesn't appear to be any way to feed a raw octet string to <code>$u.sha1()</code>; the UTF-8 conversion is done automatically, and it is very unlikely for the octet strings you need to hash in HMAC to even be the valid UTF-8 encoding of <em>any</em> Unicode string.</p> <p>If you used <a href="https://code.google.com/p/crypto-js/" rel="nofollow">CryptoJS</a> instead, however, you could convert the octet string (or the hex representation of it) to a <code>WordArray</code> and pass that directly to <code>CryptoJS.SHA1()</code>:</p> <pre><code>var words = CryptoJS.enc.Latin1.parse(ikeypmessage); hipt = CryptoJS.SHA1(words).toString(); </code></pre> <p>Of course, if you were using CryptoJS, it would be easier and more efficient to convert the key and message to <code>WordArray</code>s to begin with, and then work directly with those. Or you could just use the built-in <code>CryptoJS.HmacSHA1()</code> method.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload