(PHP 7 >= 7.2.0, PHP 8)
sodium_crypto_box — Authenticated public-key encryption
$message, string $nonce, #[\SensitiveParameter] string $key_pair): stringEncrypt a message using asymmetric (public key) cryptography.
The algorithm used by functions prefixed with sodium_crypto_box() are Elliptic Curve Diffie-Hellman over the Montgomery curve, Curve25519; usually abbreviated as X25519.
messagenoncekey_pairReturns the encrypted message (ciphertext plus authentication tag). The ciphertext will be 16 bytes longer than the plaintext, and a raw binary string. See sodium_bin2base64() for safe encoding for storage.