WordPress at a glance
function is not described

ParagonIE_Sodium_Crypto32::secretbox_open() public WP 1.0

Decrypt a ciphertext generated via secretbox().

{} It's a method of the class: ParagonIE_Sodium_Crypto32{}

No Hooks.

Return

String. Null. Nothing.

Usage

$result = ParagonIE_Sodium_Crypto32::secretbox_open( $ciphertext, $nonce, $key );
$ciphertext(string) (required)
-
$nonce(string) (required)
-
$key(string) (required)
-

Code of ParagonIE_Sodium_Crypto32::secretbox_open() WP 5.7

<?php
public static function secretbox_open($ciphertext, $nonce, $key)
{
    /** @var string $mac */
    $mac = ParagonIE_Sodium_Core32_Util::substr(
        $ciphertext,
        0,
        self::secretbox_xsalsa20poly1305_MACBYTES
    );

    /** @var string $c */
    $c = ParagonIE_Sodium_Core32_Util::substr(
        $ciphertext,
        self::secretbox_xsalsa20poly1305_MACBYTES
    );

    /** @var int $clen */
    $clen = ParagonIE_Sodium_Core32_Util::strlen($c);

    /** @var string $subkey */
    $subkey = ParagonIE_Sodium_Core32_HSalsa20::hsalsa20($nonce, $key);

    /** @var string $block0 */
    $block0 = ParagonIE_Sodium_Core32_Salsa20::salsa20(
        64,
        ParagonIE_Sodium_Core32_Util::substr($nonce, 16, 8),
        $subkey
    );
    $verified = ParagonIE_Sodium_Core32_Poly1305::onetimeauth_verify(
        $mac,
        $c,
        ParagonIE_Sodium_Core32_Util::substr($block0, 0, 32)
    );
    if (!$verified) {
        try {
            ParagonIE_Sodium_Compat::memzero($subkey);
        } catch (SodiumException $ex) {
            $subkey = null;
        }
        throw new SodiumException('Invalid MAC');
    }

    /** @var string $m - Decrypted message */
    $m = ParagonIE_Sodium_Core32_Util::xorStrings(
        ParagonIE_Sodium_Core32_Util::substr($block0, self::secretbox_xsalsa20poly1305_ZEROBYTES),
        ParagonIE_Sodium_Core32_Util::substr($c, 0, self::secretbox_xsalsa20poly1305_ZEROBYTES)
    );
    if ($clen > self::secretbox_xsalsa20poly1305_ZEROBYTES) {
        // We had more than 1 block, so let's continue to decrypt the rest.
        $m .= ParagonIE_Sodium_Core32_Salsa20::salsa20_xor_ic(
            ParagonIE_Sodium_Core32_Util::substr(
                $c,
                self::secretbox_xsalsa20poly1305_ZEROBYTES
            ),
            ParagonIE_Sodium_Core32_Util::substr($nonce, 16, 8),
            1,
            (string) $subkey
        );
    }
    return $m;
}