KRL: Signing Queries with HMAC_SHA1

I made a set of tests for mathematical functions: hmac_ * KRL. I am comparing KRL results with Python results. KRL gives me different results.

code: https://gist.github.com/980788 results: http://ktest.heroku.com/a421x68

How can I get valid signatures from KRL? I assume the Python results are correct.

UPDATE: it works great if you don't need newlines in the message. How to sign a line containing newline characters?

+3
source share
1 answer

, SHA python , b64encode. SHA, base64 , .

KRL, :
 : hmac_sha1_base64 (raw_string, );
 : hmac_sha256_base64 (raw_string, );

, Amazon, .

, RFC (sha1, sha256). , , :

HMAC SHA1

test_case = 2
key = "Jefe"
key_len = 4
data = " ?"
data_len = 28
digest = 0xeffcdf6ae5eb2fa2d27416d5f184df9c259a7c79

HMAC SHA256

= 4a656665 ( "Jefe" )
    = 7768617420646f2079612077616e7420666f72206e6f7468696e673f ( " ?" )
   HMAC-SHA-256 = 5bdcc146bf60754e6a042426089575c75a003f089d2739839dec58b964ec3843

:

global {  
        raw_string = "what do ya want for nothing?";  
        mkey = "Jefe";  
    }

rule first_rule {
        select when pageview ".*" setting ()
        pre {
            hmac_sha1 = math:hmac_sha1_hex(raw_string,mkey);
            hmac_sha1_64 = math:hmac_sha1_base64(raw_string,mkey);
            bhs256c = math:hmac_sha256_hex(raw_string,mkey);
            bhs256c64 = math:hmac_sha256_base64(raw_string,mkey);

        }
        {
        notify("HMAC sha1", "#{hmac_sha1}") with sticky = true;
        notify("hmac sha1 base 64", "#{hmac_sha1_64}") with sticky = true;
            notify("hmac sha256", "#{bhs256c}") with sticky = true;
            notify("hmac sha256 base 64", "#{bhs256c64}") with sticky = true;
        }
}

var hmac_sha1 = 'effcdf6ae5eb2fa2d27416d5f184df9c259a7c79';
var hmac_sha1_64 = '7/zfauXrL6LSdBbV8YTfnCWafHk';
var bhs256c = '5bdcc146bf60754e6a042426089575c75a003f089d2739839dec58b964ec3843';
var bhs256c64 = 'W9zBRr9gdU5qBCQmCJV1x1oAPwidJzmDnexYuWTsOEM';

HEX SHA1 SHA256 .

base64, HEX encoder base64

:

7/zfauXrL6LSdBbV8YTfnCWafHk =
W9zBRr9gdU5qBCQmCJV1x1oAPwidJzmDnexYuWTsOEM =

HMAC SHA1 base64 HMAC SHA256 base64 .

, base64 SHA python , ?

+2

All Articles