Skip to content

Instantly share code, notes, and snippets.

@turret-io
turret-io / slackNotify.js
Last active Dec 22, 2016
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 / aes_enc_dec.php
Last active May 17, 2022
AES encryption/decryption in PHP
View aes_enc_dec.php
<?php
// DEFINE our cipher
define('AES_256_CBC', 'aes-256-cbc');
// Generate a 256-bit encryption key
// This should be stored somewhere instead of recreating it each time
$encryption_key = openssl_random_pseudo_bytes(32);
// Generate an initialization vector
// This *MUST* be available for decryption as well
@turret-io
turret-io / verify_hmac.js
Last active May 4, 2022
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.js
Created Sep 24, 2014
Generate HMAC in NodeJS
View gen_hmac.js
var crypto = require('crypto');
var SHARED_SECRET = "sup3rs3cr3t!!";
function signString(string_to_sign, shared_secret) {
var hmac = crypto.createHmac('sha512', shared_secret);
hmac.write(string_to_sign);
hmac.end()
return hmac.read();
}
@turret-io
turret-io / verify_hmac.php
Last active Sep 15, 2022
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);
@turret-io
turret-io / gen_hmac.php
Created Sep 24, 2014
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.rb
Last active Dec 1, 2020
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 / gen_hmac.rb
Created Sep 24, 2014
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 / verify_hmac.py
Last active Jan 24, 2022
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 / gen_hmac.py
Created Sep 24, 2014
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',