- random_bytes: documentation ( source)
<?php
// Some example variables:
$alice_ecdh_secret =
"Hallo";
$bob_ecdh_public =
"Welt";
$message_keypair = sodium_crypto_box_keypair_from_secretkey_and_publickey(
$alice_ecdh_secret,
$bob_ecdh_public
);
$plaintext = "This is a secret message for your eyes only.";
$nonce = random_bytes(24);
// And now for the actual public-key encryption step:
$ciphertext = sodium_crypto_box($plaintext, $nonce, $message_keypair);