函数名称:sodium_crypto_aead_aes256gcm_decrypt()
函数描述:该函数用于使用AES-256-GCM解密经过AEAD(认证加密关联数据)加密的数据。
适用版本:PHP 7.2.0及以上版本。
语法:sodium_crypto_aead_aes256gcm_decrypt(string $ciphertext, string $additional_data, string $nonce, string $key): string|false
参数:
返回值:
示例:
$ciphertext = hex2bin('2b7e151628aed2a6abf7158809cf4f3c');
$additional_data = hex2bin('f0f1f2f3f4f5f6f7f8f9');
$nonce = hex2bin('0708090a0b0c0d0e0f10111213141516171819');
$key = hex2bin('000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f');
$plaintext = sodium_crypto_aead_aes256gcm_decrypt($ciphertext, $additional_data, $nonce, $key);
if ($plaintext === false) {
echo "解密失败";
} else {
echo "解密成功,明文数据为:" . $plaintext;
}
注意事项: