public static function ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_encrypt in Automatic Updates 7
Same name and namespace in other branches
- 8 vendor/paragonie/sodium_compat/src/Compat.php \ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_encrypt()
Authenticated Encryption with Associated Data
Algorithm: ChaCha20-Poly1305
This mode uses a 64-bit random nonce with a 64-bit counter. IETF mode uses a 96-bit random nonce with a 32-bit counter.
@psalm-suppress MixedArgument
Parameters
string $plaintext Message to be encrypted:
string $assocData Authenticated Associated Data (unencrypted):
string $nonce Number to be used only Once; must be 8 bytes:
string $key Encryption key:
Return value
string Ciphertext with a 16-byte Poly1305 message authentication code appended
Throws
SodiumException
TypeError
2 calls to ParagonIE_Sodium_Compat::crypto_aead_chacha20poly1305_encrypt()
- php72compat.php in vendor/
paragonie/ sodium_compat/ lib/ php72compat.php - sodium_compat.php in vendor/
paragonie/ sodium_compat/ lib/ sodium_compat.php
File
- vendor/
paragonie/ sodium_compat/ src/ Compat.php, line 555
Class
Code
public static function crypto_aead_chacha20poly1305_encrypt($plaintext = '', $assocData = '', $nonce = '', $key = '') {
/* Type checks: */
ParagonIE_Sodium_Core_Util::declareScalarType($plaintext, 'string', 1);
ParagonIE_Sodium_Core_Util::declareScalarType($assocData, 'string', 2);
ParagonIE_Sodium_Core_Util::declareScalarType($nonce, 'string', 3);
ParagonIE_Sodium_Core_Util::declareScalarType($key, 'string', 4);
/* Input validation: */
if (ParagonIE_Sodium_Core_Util::strlen($nonce) !== self::CRYPTO_AEAD_CHACHA20POLY1305_NPUBBYTES) {
throw new SodiumException('Nonce must be CRYPTO_AEAD_CHACHA20POLY1305_NPUBBYTES long');
}
if (ParagonIE_Sodium_Core_Util::strlen($key) !== self::CRYPTO_AEAD_CHACHA20POLY1305_KEYBYTES) {
throw new SodiumException('Key must be CRYPTO_AEAD_CHACHA20POLY1305_KEYBYTES long');
}
if (self::useNewSodiumAPI()) {
return (string) sodium_crypto_aead_chacha20poly1305_encrypt($plaintext, $assocData, $nonce, $key);
}
if (self::use_fallback('crypto_aead_chacha20poly1305_encrypt')) {
return (string) call_user_func('\\Sodium\\crypto_aead_chacha20poly1305_encrypt', $plaintext, $assocData, $nonce, $key);
}
if (PHP_INT_SIZE === 4) {
return ParagonIE_Sodium_Crypto32::aead_chacha20poly1305_encrypt($plaintext, $assocData, $nonce, $key);
}
return ParagonIE_Sodium_Crypto::aead_chacha20poly1305_encrypt($plaintext, $assocData, $nonce, $key);
}