Sodium Test
This file contains 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 | |
if (sodium_crypto_aead_aes256gcm_is_available()) { | |
echo 'sodium_crypto_aead_aes256gcm_is_available is true'.PHP_EOL; | |
} else { | |
echo 'sodium_crypto_aead_aes256gcm_is_available is false'.PHP_EOL; | |
} | |
//echo 'Generated key with sodium_crypto_aead_aes256gcm_keygen is: ' . sodium_crypto_aead_aes256gcm_keygen() . PHP_EOL; | |
$msg = 'john.doe@example.com'; | |
$nonce = 'blablablabla'; | |
$nonce2 = 'blablablabl2'; | |
$key = 'SODIUM_CRYPTO_AEAD_AES256GCM_KEY'; | |
echo SODIUM_CRYPTO_AEAD_AES256GCM_NPUBBYTES . PHP_EOL; | |
echo SODIUM_CRYPTO_AEAD_AES256GCM_KEYBYTES . PHP_EOL; | |
$cipher = sodium_crypto_aead_aes256gcm_encrypt($msg, null, $nonce, $key); | |
echo $cipher . PHP_EOL; | |
echo base64_encode($cipher) . PHP_EOL; | |
$decoded_cipher = base64_decode(base64_encode($cipher)); | |
$plaintext = sodium_crypto_aead_aes256gcm_decrypt($decoded_cipher, null, $nonce, $key); | |
echo $plaintext . PHP_EOL; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment