ParagonIE_Sodium_Compat::crypto_aead_aes256gcm_encrypt() public WP 1.0
Authenticated Encryption with Associated Data: Encryption
Algorithm:
AES-256-GCM
{} It's a method of the class: ParagonIE_Sodium_Compat{}
No Hooks.
Return
String
. Ciphertext with a 16-byte GCM message authentication code appended
Usage
$result = ParagonIE_Sodium_Compat::crypto_aead_aes256gcm_encrypt(;
Code of ParagonIE_Sodium_Compat::crypto_aead_aes256gcm_encrypt() ParagonIE Sodium Compat::crypto aead aes256gcm encrypt WP 5.7
public static function crypto_aead_aes256gcm_encrypt(
$plaintext = '',
$assocData = '',
$nonce = '',
$key = ''
) {
if (!self::crypto_aead_aes256gcm_is_available()) {
throw new SodiumException('AES-256-GCM is not available');
}
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_AES256GCM_NPUBBYTES) {
throw new SodiumException('Nonce must be CRYPTO_AEAD_AES256GCM_NPUBBYTES long');
}
if (ParagonIE_Sodium_Core_Util::strlen($key) !== self::CRYPTO_AEAD_AES256GCM_KEYBYTES) {
throw new SodiumException('Key must be CRYPTO_AEAD_AES256GCM_KEYBYTES long');
}
if (!is_callable('openssl_encrypt')) {
throw new SodiumException('The OpenSSL extension is not installed, or openssl_encrypt() is not available');
}
$authTag = '';
$ciphertext = openssl_encrypt(
$plaintext,
'aes-256-gcm',
$key,
OPENSSL_RAW_DATA,
$nonce,
$authTag,
$assocData
);
return $ciphertext . $authTag;
}