3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * La fonction sodium_crypto_box_keypair() génère aléatoirement une clé secrète * et une clé publique correspondante. */ $aliceKeypair = sodium_crypto_box_keypair(); $alicePublicKey = sodium_crypto_box_publickey($aliceKeypair); $aliceSecretKey = sodium_crypto_box_secretkey($aliceKeypair); $bobKeypair = sodium_crypto_box_keypair(); $bobPublicKey = sodium_crypto_box_publickey($bobKeypair); $bobSecretKey = sodium_crypto_box_secretkey($bobKeypair); /** * Le nombre arbitraire n'a pas besoin d'être confidentiel, mais il doit être * utilisé avec une seule invocation de crypto_box_open() pour une paire * particulière de clés publiques et secrètes. */ $nonce = random_bytes(SODIUM_CRYPTO_SECRETBOX_NONCEBYTES); $aliceToBobKeyPair = sodium_crypto_box_keypair_from_secretkey_and_publickey($aliceSecretKey, $bobPublicKey); $message = 'Signed using Alice\'s secret key and to be encrypted using Bob\'s public key.'; $ciphertext = sodium_crypto_box($message, $nonce, $aliceToBobKeyPair); $bobToAliceKp = sodium_crypto_box_keypair_from_secretkey_and_publickey($bobSecretKey, $alicePublicKey); $plaintext = sodium_crypto_box_open($ciphertext, $nonce, $bobToAliceKp); echo $plaintext;
Output for 7.2.0 - 7.2.26, 7.3.0 - 7.3.13, 7.4.0 - 7.4.1
Signed using Alice's secret key and to be encrypted using Bob's public key.
Output for 7.0.0 - 7.0.33, 7.1.0 - 7.1.33
Fatal error: Uncaught Error: Call to undefined function sodium_crypto_box_keypair() in /in/UtnS7:7 Stack trace: #0 {main} thrown in /in/UtnS7 on line 7
Process exited with code 255.
Output for 5.6.0 - 5.6.40
Fatal error: Call to undefined function sodium_crypto_box_keypair() in /in/UtnS7 on line 7
Process exited with code 255.

preferences:
127.11 ms | 401 KiB | 157 Q