函数:sodium_crypto_sign_open()
适用版本:PHP 7.2.0 及以上
用法:sodium_crypto_sign_open() 函数用于验证由 sodium_crypto_sign_detached() 函数生成的数字签名,并返回原始消息。
语法:sodium_crypto_sign_open(string $signature, string $public_key) : string|bool
参数:
返回值:
示例:
// 公钥和签名的二进制字符串 $publicKey = hex2bin('4a9d9b9d9e8e54d1e2a3f4a9d9b9d9e8e54d1e2a3f4a9d9b9d9e8e54d1e2a3f'); $signature = hex2bin('4a9d9b9d9e8e54d1e2a3f4a9d9b9d9e8e54d1e2a3f4a9d9b9d9e8e54d1e2a3f');
// 需要验证的消息 $message = "Hello, world!";
// 验证签名并返回原始消息 $originalMessage = sodium_crypto_sign_open($signature, $publicKey);
if ($originalMessage !== false) { echo "消息验证成功:". $originalMessage; } else { echo "消息验证失败!"; }
注意事项: