Skip to content

Instantly share code, notes, and snippets.

View locked's full-sized avatar

Adam Etienne locked

View GitHub Profile
@locked
locked / gist:b537bf726f94a1c51fbf
Created March 6, 2016 16:49
AES CBC PHP & CLI
// This code generate AES block compatible with how Go does things
$string = "string to encrypt";
$key = "my secret key";
$iv = openssl_random_pseudo_bytes(16);
echo base64_encode($iv.openssl_encrypt($string, "aes-256-cbc", $key, OPENSSL_RAW_DATA, $iv));
// The shell equivalent:
// echo 'string to encrypt' | openssl enc -aes-256-cbc -nosalt -K $KEY -iv acfa7a047800b2f221f2c4f7d626eafb | base64
// In which:
@locked
locked / gist:b066aa1ddeb2b28e855e
Created March 6, 2016 16:44
Go AES CBC Examples
package main
import (
"crypto/aes"
"crypto/cipher"
"fmt"
"crypto/rand"
"io"
"encoding/base64"
"encoding/hex"