Created
February 11, 2017 22:58
-
-
Save paragonie-scott/bb852d8f5462635f4a181f7843799a90 to your computer and use it in GitHub Desktop.
Is libsodium's AES-256-GCM compatible with OpenSSL?
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
<?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