php教程

sodium_crypto_auth

(PHP 7 >= 7.2.0)

sodium_crypto_authCompute a tag for the message

说明

sodium_crypto_auth ( string $msg , string $key ) : string

Warning

本函数还未编写文档,仅有参数列表。

参数

msg

key

返回值

User Contributed Notes

craig at craigfrancis dot co dot uk 25-Aug-2018 08:08
Here's a quick example on how to use sodium_crypto_auth(); where you have a message that you want to sign, so anyone who can access the *shared* key can confirm that the message hasn't been tampered with.

This is similar to sodium_crypto_sign_detached(), but both signer and verifier have access to the same key.

<?php

$key
= sodium_crypto_auth_keygen();

//--------------------------------------------------
// Person 1, signing

$message = 'Hello';

$signature = sodium_crypto_auth($message, $key);

//--------------------------------------------------
// Person 2, verifying

$message_valid = sodium_crypto_auth_verify($signature, $message, $key);

if (!
$message_valid) {
    exit(
'Message has been changed.');
}

?>

CopyRight © 2008-2022 verySource.Com All Rights reserved. 京ICP备17048824号-1 京公网安备:11010502034788