Skip to content

Instantly share code, notes, and snippets.

@paragonie-scott
Created February 11, 2017 22:58
Show Gist options
  • Save paragonie-scott/bb852d8f5462635f4a181f7843799a90 to your computer and use it in GitHub Desktop.
Save paragonie-scott/bb852d8f5462635f4a181f7843799a90 to your computer and use it in GitHub Desktop.
Is libsodium's AES-256-GCM compatible with OpenSSL?
<?php
$message = random_bytes(1024);
$key = random_bytes(32);
$nonce = random_bytes(12);
$tag = '';
$aad = random_bytes(random_int(1, 127));
$cipher = openssl_encrypt($message, 'aes-256-gcm', $key, OPENSSL_RAW_DATA, $nonce, $tag, $aad, 16);
$plaintext = \Sodium\crypto_aead_aes256gcm_decrypt(
$cipher . $tag,
$aad,
$nonce,
$key
);
var_dump($plaintext === $message);
/* bool(true) */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment