Blog 2019/2/1
<- previous | index | next ->
HMACs came up in a discussion at work so I threw together a few quick demos of how to generate them using the built-in API's of a few langs.
Blog 2019/2/1
<- previous | index | next ->
HMACs came up in a discussion at work so I threw together a few quick demos of how to generate them using the built-in API's of a few langs.
| var crypto = require("crypto"); | |
| var message = "a message which needs an hmac"; | |
| var key = "keyser soze"; | |
| var hmac_hex = crypto.createHmac("sha256", key).update(message).digest("hex"); | |
| console.log(hmac_hex); |
| <? | |
| $message = "a message which needs an hmac"; | |
| $key = "keyser soze"; | |
| $hmac_hex = hash_hmac("sha256", $message, $key); | |
| print_r($hmac_hex); | |
| ?> |
| #!/usr/bin/env python | |
| import hmac | |
| import hashlib | |
| message = "a message which needs an hmac" | |
| key = "keyser soze" | |
| hmac_hex = hmac.new(key, message, hashlib.sha256).hexdigest() | |
| print hmac_hex |
| $ ./run.sh | |
| f42febfb52f8d2853452b1c835947d70b3e92b1da5ba0c9568b50e531b88bc5b | |
| f42febfb52f8d2853452b1c835947d70b3e92b1da5ba0c9568b50e531b88bc5b | |
| f42febfb52f8d2853452b1c835947d70b3e92b1da5ba0c9568b50e531b88bc5b |
| #!/bin/sh | |
| set -e | |
| node demo.js | |
| php demo.php | |
| python demo.py |