ParagonIE_Sodium_Compat::crypto_box()public staticWP 1.0

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

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.

{} Это метод класса: ParagonIE_Sodium_Compat{}

Хуков нет.


Строку. Ciphertext with 16-byte Poly1305 MAC


$result = ParagonIE_Sodium_Compat::crypto_box( $plaintext, $nonce, $keypair );
$plaintext(строка) (обязательный)
The message to be encrypted
$nonce(строка) (обязательный)
A Number to only be used Once; must be 24 bytes
$keypair(строка) (обязательный)
Your secret key and your recipient's public key

Код ParagonIE_Sodium_Compat::crypto_box() WP 6.0

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);