PHP Conference Fukuoka 2025

sodium_crypto_sign

(PHP 7 >= 7.2.0, PHP 8)

sodium_crypto_signFirma un mensaje

Descripción

sodium_crypto_sign(string $message, #[\SensitiveParameter] string $secret_key): string

Firma un mensaje con una clave secreta, que puede ser verificada por la clave pública correspondiente. Esta función adjunta la firma al mensaje. Ver sodium_crypto_sign_detached() para las firmas desvinculadas.

Parámetros

message

El mensaje a firmar.

secret_key

La clave secreta. Ver sodium_crypto_sign_secretkey()

Valores devueltos

El mensaje firmado (no cifrado).

add a note

User Contributed Notes 1 note

up
3
craig at craigfrancis dot co dot uk
7 years ago
Here's a quick example on how to use sodium_crypto_sign(); where you have a message that you want to sign, so anyone with the public key can confirm that the message hasn't been tampered with.This is similar to sodium_crypto_sign_detached(), but the returned string contains the original message as well (in plain text, at the end, so anyone can read it).<?php// $sign_seed = random_bytes(SODIUM_CRYPTO_SIGN_SEEDBYTES);// $sign_pair = sodium_crypto_sign_seed_keypair($sign_seed);$sign_pair = sodium_crypto_sign_keypair();$sign_secret = sodium_crypto_sign_secretkey($sign_pair);$sign_public = sodium_crypto_sign_publickey($sign_pair);//--------------------------------------------------// Person 1, signing$message = 'Hello';$message_signed = sodium_crypto_sign($message, $sign_secret);//--------------------------------------------------// Person 2, verifying$message = sodium_crypto_sign_open($message_signed, $sign_public);echo $message . "\n";?>
To Top