Skip to content

Instantly share code, notes, and snippets.

View paulgullett's full-sized avatar

paulgullett

View GitHub Profile
@eoli3n
eoli3n / encryption.php
Last active May 28, 2024 02:47
Encrypt - Decrypt AES from/to Python PyCryptodome from/to PHP openssl
<?php
// use to generate key : 'openssl rand -hex 32'
function my_encrypt($data, $passphrase) {
$secret_key = hex2bin($passphrase);
$iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length('aes-256-cbc'));
$encrypted_64 = openssl_encrypt($data, 'aes-256-cbc', $secret_key, 0, $iv);
$iv_64 = base64_encode($iv);
$json = new stdClass();
$json->iv = $iv_64;