Last active
December 11, 2015 08:08
-
-
Save visibletrap/4571244 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn hex-hmac-sha1 [key input] | |
(let [secret (javax.crypto.spec.SecretKeySpec. (. key getBytes "UTF-8") "HmacSHA1") | |
hmac-sha1 (doto (javax.crypto.Mac/getInstance "HmacSHA1") (.init secret)) | |
bytes (. hmac-sha1 doFinal (. input getBytes "UTF-8")) | |
hex (apply str (map (partial format "%02x") bytes))] | |
hex)) | |
(hex-hmac-sha1 "secret-key" "string-to-sign") | |
; => "0b6afb06cd51b2713cf18d99f7f0228d06effd46" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'openssl' | |
sha1 = OpenSSL::Digest::Digest.new('sha1') | |
OpenSSL::HMAC.hexdigest(sha1, 'secret-key', 'string-to-sign') | |
# => "0b6afb06cd51b2713cf18d99f7f0228d06effd46" |
@hybridknight lua สั้นลงได้อีกนิดนึงนะ :P
require("crypto").hmac.digest("sha1", "string-to-sign", "secret-key")
// => '0b6afb06cd51b2713cf18d99f7f0228d06effd46'
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
require('crypto').createHmac('sha1', 'secret-key').update('string-to-sign').digest('hex')
// => '0b6afb06cd51b2713cf18d99f7f0228d06effd46'