ParagonIE_Sodium_Crypto::aead_chacha20poly1305_encrypt() public WP 1.0
AEAD Encryption with ChaCha20-Poly1305
{} Это метод класса: ParagonIE_Sodium_Crypto{}
Хуков нет.
Возвращает
Строку.
Использование
$result = ParagonIE_Sodium_Crypto::aead_chacha20poly1305_encrypt(;
Код ParagonIE_Sodium_Crypto::aead_chacha20poly1305_encrypt() ParagonIE Sodium Crypto::aead chacha20poly1305 encrypt WP 5.6.2
public static function aead_chacha20poly1305_encrypt(
$message = '',
$ad = '',
$nonce = '',
$key = ''
) {
/** @var int $len - Length of the plaintext message */
$len = ParagonIE_Sodium_Core_Util::strlen($message);
/** @var int $adlen - Length of the associated data */
$adlen = ParagonIE_Sodium_Core_Util::strlen($ad);
/** @var string The first block of the chacha20 keystream, used as a poly1305 key */
$block0 = ParagonIE_Sodium_Core_ChaCha20::stream(
32,
$nonce,
$key
);
$state = new ParagonIE_Sodium_Core_Poly1305_State($block0);
try {
ParagonIE_Sodium_Compat::memzero($block0);
} catch (SodiumException $ex) {
$block0 = null;
}
/** @var string $ciphertext - Raw encrypted data */
$ciphertext = ParagonIE_Sodium_Core_ChaCha20::streamXorIc(
$message,
$nonce,
$key,
ParagonIE_Sodium_Core_Util::store64_le(1)
);
$state->update($ad);
$state->update(ParagonIE_Sodium_Core_Util::store64_le($adlen));
$state->update($ciphertext);
$state->update(ParagonIE_Sodium_Core_Util::store64_le($len));
return $ciphertext . $state->finish();
}