Skip to content

Instantly share code, notes, and snippets.

@turret-io
turret-io / gen_hmac.go
Created September 24, 2014 15:28
Generate HMAC in Go
View gen_hmac.go
package main
import (
"crypto/hmac"
"crypto/sha512"
"encoding/base64"
"encoding/json"
"fmt"
"strconv"
"time"
@turret-io
turret-io / verify_hmac.go
Last active August 29, 2015 14:06
Verify HMAC in Go
View verify_hmac.go
package main
import (
"crypto/hmac"
"crypto/sha512"
"encoding/base64"
"encoding/json"
"errors"
"fmt"
"net/url"
@turret-io
turret-io / gen_hmac.py
Created September 24, 2014 15:30
Generate HMAC in Python
View gen_hmac.py
import hmac, hashlib, json, time, base64
SHARED_SECRET = 'sup3rs3cr3t!!'
def signString(string_to_sign, shared_secret):
return hmac.new(shared_secret, string_to_sign, hashlib.sha512).digest()
if __name__ == '__main__':
payload = {
'name': 'joe smith',
@turret-io
turret-io / gen_hmac.rb
Created September 24, 2014 15:31
Generate HMAC in Ruby
View gen_hmac.rb
require 'digest'
require 'base64'
require 'cgi'
require 'time'
require 'openssl'
require 'json'
SHARED_SECRET = 'sup3rs3cr3t!!'
def signString(string_to_sign, shared_secret)
@turret-io
turret-io / slackNotify.js
Last active December 22, 2016 16:16
Parse SNS notification from Elastic Beanstalk and publish to Slack channel
View slackNotify.js
var http = require('https');
// Create Slack channel -> Slack URL mapping
// This incoming webhook URL is provided when adding a Slack integration
var config = {
'#mychannel': 'https://hooks.slack.com/services/YOUR/SLACK/HOOK_HERE',
};
/*
Convenience method to fetch the channel's URL
@turret-io
turret-io / verify_hmac.rb
Last active December 1, 2020 09:51
Verify HMAC in Ruby
View verify_hmac.rb
require 'digest'
require 'base64'
require 'cgi'
require 'uri'
require 'time'
require 'openssl'
require 'json'
require 'active_support/security_utils'
SHARED_SECRET = 'sup3rs3cr3t!!'
@turret-io
turret-io / verify_hmac.py
Last active January 24, 2022 09:47
Verify HMAC in Python
View verify_hmac.py
import hmac, hashlib, json, time, base64, urlparse
SHARED_SECRET = 'sup3rs3cr3t!!'
def verifySignature(string_to_verify, signature, shared_secret):
return ct_compare(hmac.new(shared_secret,
string_to_verify, hashlib.sha512).digest(), signature)
def verifyTime(decoded_json):
j = json.loads(decoded_json)
@turret-io
turret-io / verify_hmac.js
Last active May 4, 2022 14:52
Verify HMAC in NodeJS
View verify_hmac.js
var crypto = require('crypto');
// Added for safer string equality checking
var bufferEq = require('buffer-equal-constant-time');
var url = require('url');
var SHARED_SECRET = "sup3rs3cr3t!!";
function verifySignature(string_to_sign, signature, shared_secret) {
var hmac = crypto.createHmac('sha512', shared_secret);
hmac.write(string_to_sign);
hmac.end()
@turret-io
turret-io / gen_hmac.php
Created September 24, 2014 15:32
Generate HMAC in PHP
View gen_hmac.php
<?php
define("SHARED_SECRET", "sup3rs3cr3t!!");
function signString($string_to_sign, $shared_secret) {
return hash_hmac("sha512", $string_to_sign, $shared_secret);
}
$payload = array(
@turret-io
turret-io / verify_hmac.php
Last active April 10, 2023 17:45
Verify HMAC in PHP
View verify_hmac.php
<?php
define("SHARED_SECRET", "sup3rs3cr3t!!");
if(!function_exists('hash_equals')) {
function hash_equals($str1, $str2) {
// Run constant-time comparison for PHP < 5.6 which doesn't support hmac_equals
$str1_len = strlen($str1);
$str2_len = strlen($str2);