This file contains hidden or 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
// 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: |
This file contains hidden or 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
package main | |
import ( | |
"crypto/aes" | |
"crypto/cipher" | |
"fmt" | |
"crypto/rand" | |
"io" | |
"encoding/base64" | |
"encoding/hex" |