sodium_crypto_auth

(PHP 7 >= 7.2.0, PHP 8)

sodium_crypto_authメッセージに対応するタグを計算する

説明

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

対称鍵によるメッセージ認証を行います。 sodium_crypto_auth() は完全性は提供しますが、機密性は提供しません。

(sodium_crypto_sign_detached() のような) 電子署名と異なり、 メッセージを検証する側は、 自分たちのメッセージを認証することもできます。 (つまり、対称鍵による認証です)

パラメータ

message

認証したいメッセージ

key

認証鍵

戻り値

認証タグを返します。

add a note add a note

User Contributed Notes 1 note

up
1
craig at craigfrancis dot co dot uk
5 years ago
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.');
}

?>
To Top