Summery Summery

Decrypts a message previously encrypted with crypto_secretbox().

Syntax Syntax

ParagonIE_Sodium_Compat::crypto_secretbox_open( string $ciphertext, string $nonce, string $key )

Parameters Parameters


(string) (Required) Ciphertext with Poly1305 MAC


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


(string) (Required) Symmetric encryption key

Return Return

(string) Original plaintext message

Source Source

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

    public static function crypto_secretbox_open($ciphertext, $nonce, $key)
        /* Type checks: */
        ParagonIE_Sodium_Core_Util::declareScalarType($ciphertext, 'string', 1);
        ParagonIE_Sodium_Core_Util::declareScalarType($nonce, 'string', 2);
        ParagonIE_Sodium_Core_Util::declareScalarType($key, 'string', 3);

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

        if (self::useNewSodiumAPI()) {
             * @psalm-suppress InvalidReturnStatement
             * @psalm-suppress FalsableReturnStatement
            return sodium_crypto_secretbox_open($ciphertext, $nonce, $key);
        if (self::use_fallback('crypto_secretbox_open')) {
            return call_user_func('\\Sodium\\crypto_secretbox_open', $ciphertext, $nonce, $key);
        if (PHP_INT_SIZE === 4) {
            return ParagonIE_Sodium_Crypto32::secretbox_open($ciphertext, $nonce, $key);
        return ParagonIE_Sodium_Crypto::secretbox_open($ciphertext, $nonce, $key);



Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.