函数名称:sodium_crypto_stream_xchacha20_xor()
适用版本:PHP 7.2.0及以上版本
函数描述:该函数用于生成一个XChaCha20流加密的密文,通过将明文与密钥进行异或运算来实现加密。
用法:
string sodium_crypto_stream_xchacha20_xor(string $message, string $nonce, string $key)
参数:
返回值:
示例:
$message = "Hello, world!";
$nonce = random_bytes(SODIUM_CRYPTO_STREAM_XCHACHA20_NONCEBYTES);
$key = random_bytes(SODIUM_CRYPTO_STREAM_XCHACHA20_KEYBYTES);
$ciphertext = sodium_crypto_stream_xchacha20_xor($message, $nonce, $key);
echo "明文: " . $message . PHP_EOL;
echo "密文: " . bin2hex($ciphertext) . PHP_EOL;
注意事项: