Summery Summery

Authenticated asymmetric-key encryption. Both the sender and recipient may decrypt messages.

Syntax Syntax

ParagonIE_Sodium_Compat::crypto_box( string $plaintext, string $nonce, string $keypair )

Description Description

Algorithm: X25519-XSalsa20-Poly1305. X25519: Elliptic-Curve Diffie Hellman over Curve25519. XSalsa20: Extended-nonce variant of salsa20. Poyl1305: Polynomial MAC for one-time message authentication.

Parameters Parameters


(Required) The message to be encrypted


(Required) A Number to only be used Once; must be 24 bytes


(Required) Your secret key and your recipient's public key

Return Return

(string) Ciphertext with 16-byte Poly1305 MAC

Source Source

File: wp-includes/sodium_compat/src/Compat.php

    public static function crypto_box($plaintext, $nonce, $keypair)
        /* Type checks: */
        ParagonIE_Sodium_Core_Util::declareScalarType($plaintext, 'string', 1);
        ParagonIE_Sodium_Core_Util::declareScalarType($nonce, 'string', 2);
        ParagonIE_Sodium_Core_Util::declareScalarType($keypair, 'string', 3);

        /* Input validation: */
        if (ParagonIE_Sodium_Core_Util::strlen($nonce) !== self::CRYPTO_BOX_NONCEBYTES) {
            throw new SodiumException('Argument 2 must be CRYPTO_BOX_NONCEBYTES long.');
        if (ParagonIE_Sodium_Core_Util::strlen($keypair) !== self::CRYPTO_BOX_KEYPAIRBYTES) {
            throw new SodiumException('Argument 3 must be CRYPTO_BOX_KEYPAIRBYTES long.');

        if (self::useNewSodiumAPI()) {
            return (string) sodium_crypto_box($plaintext, $nonce, $keypair);
        if (self::use_fallback('crypto_box')) {
            return (string) call_user_func('\\Sodium\\crypto_box', $plaintext, $nonce, $keypair);
        if (PHP_INT_SIZE === 4) {
            return ParagonIE_Sodium_Crypto32::box($plaintext, $nonce, $keypair);
        return ParagonIE_Sodium_Crypto::box($plaintext, $nonce, $keypair);



Leave a Reply