Skip to content

Instantly share code, notes, and snippets.

@turret-io
turret-io / slackNotify.js
Last active December 22, 2016 16:16
Parse SNS notification from Elastic Beanstalk and publish to Slack channel
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 September 4, 2023 00:10
AES encryption/decryption in 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 14:52
Verify HMAC in NodeJS
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 September 24, 2014 15:32
Generate HMAC in NodeJS
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 April 10, 2023 17:45
Verify HMAC in 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 September 24, 2014 15:32
Generate HMAC in 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 December 1, 2020 09:51
Verify HMAC in Ruby
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 September 24, 2014 15:31
Generate HMAC in Ruby
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 January 24, 2022 09:47
Verify HMAC in Python
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 September 24, 2014 15:30
Generate HMAC in Python
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',