sodium_crypto_auth

(PHP 7 >= 7.2.0, PHP 8)

sodium_crypto_authCalcula una etiqueta para el mensaje

Descripción

sodium_crypto_auth(string $message, #[\SensitiveParameter] string $key): string

El mensaje de autenticación simétrica a través de sodium_crypto_auth() proporciona integridad, pero no confidencialidad.

A diferencia de las firmas digitales (por ejemplo sodium_crypto_sign_detached()), cualquier parte capaz de verificar un mensaje también es capaz de autenticar sus propios mensajes. (De ahí, la autenticación simétrica.)

Parámetros

message

El mensaje que se desea autenticar

key

La clave de autenticación

Valores devueltos

La clave de autenticación

add a note

User Contributed Notes 1 note

up
1
craig at craigfrancis dot co dot uk
6 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