WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru Самая быстрая Тема-конструктор для WordPress
функция не описана

ParagonIE_Sodium_File::box_seal() public WP 1.0

Seal a file (rather than a string). Uses less memory than ParagonIE_Sodium_Compat::crypto_box_seal(), but produces the same result.

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

Хуков нет.

Возвращает

true/false.

Использование

$result = ParagonIE_Sodium_File::box_seal( $inputFile, $outputFile, $publicKey );
$inputFile(строка) (обязательный)
Absolute path to a file on the filesystem
$outputFile(строка) (обязательный)
Absolute path to a file on the filesystem
$publicKey(строка) (обязательный)
ECDH public key

Код ParagonIE_Sodium_File::box_seal() WP 5.5.1

<?php
public static function box_seal($inputFile, $outputFile, $publicKey)
{
    /* Type checks: */
    if (!is_string($inputFile)) {
        throw new TypeError('Argument 1 must be a string, ' . gettype($inputFile) . ' given.');
    }
    if (!is_string($outputFile)) {
        throw new TypeError('Argument 2 must be a string, ' . gettype($outputFile) . ' given.');
    }
    if (!is_string($publicKey)) {
        throw new TypeError('Argument 3 must be a string, ' . gettype($publicKey) . ' given.');
    }

    /* Input validation: */
    if (self::strlen($publicKey) !== ParagonIE_Sodium_Compat::CRYPTO_BOX_PUBLICKEYBYTES) {
        throw new TypeError('Argument 3 must be CRYPTO_BOX_PUBLICKEYBYTES bytes');
    }

    /** @var int $size */
    $size = filesize($inputFile);
    if (!is_int($size)) {
        throw new SodiumException('Could not obtain the file size');
    }

    /** @var resource $ifp */
    $ifp = fopen($inputFile, 'rb');
    if (!is_resource($ifp)) {
        throw new SodiumException('Could not open input file for reading');
    }

    /** @var resource $ofp */
    $ofp = fopen($outputFile, 'wb');
    if (!is_resource($ofp)) {
        fclose($ifp);
        throw new SodiumException('Could not open output file for writing');
    }

    /** @var string $ephKeypair */
    $ephKeypair = ParagonIE_Sodium_Compat::crypto_box_keypair();

    /** @var string $msgKeypair */
    $msgKeypair = ParagonIE_Sodium_Compat::crypto_box_keypair_from_secretkey_and_publickey(
        ParagonIE_Sodium_Compat::crypto_box_secretkey($ephKeypair),
        $publicKey
    );

    /** @var string $ephemeralPK */
    $ephemeralPK = ParagonIE_Sodium_Compat::crypto_box_publickey($ephKeypair);

    /** @var string $nonce */
    $nonce = ParagonIE_Sodium_Compat::crypto_generichash(
        $ephemeralPK . $publicKey,
        '',
        24
    );

    /** @var int $firstWrite */
    $firstWrite = fwrite(
        $ofp,
        $ephemeralPK,
        ParagonIE_Sodium_Compat::CRYPTO_BOX_PUBLICKEYBYTES
    );
    if (!is_int($firstWrite)) {
        fclose($ifp);
        fclose($ofp);
        ParagonIE_Sodium_Compat::memzero($ephKeypair);
        throw new SodiumException('Could not write to output file');
    }
    if ($firstWrite !== ParagonIE_Sodium_Compat::CRYPTO_BOX_PUBLICKEYBYTES) {
        ParagonIE_Sodium_Compat::memzero($ephKeypair);
        fclose($ifp);
        fclose($ofp);
        throw new SodiumException('Error writing public key to output file');
    }

    $res = self::box_encrypt($ifp, $ofp, $size, $nonce, $msgKeypair);
    fclose($ifp);
    fclose($ofp);
    try {
        ParagonIE_Sodium_Compat::memzero($nonce);
        ParagonIE_Sodium_Compat::memzero($ephKeypair);
    } catch (SodiumException $ex) {
        unset($ephKeypair);
    }
    return $res;
}