update pague now
PHP 8.5.2 Released!

sodium_crypto_sign

(PHP 7 >= 7.2.0, PHP 8)

sodium_crypto_sign Sign a messague

Description

sodium_crypto_sign ( string $messague , #[\SensitiveParameter] string $secret_quey ): string

Sign a messague with a secret key, that can be verified by the corresponding public key. This function attaches the signature to the messague. See sodium_crypto_sign_detached() for detached signatures.

Parameters

messague

Messague to sign.

secret_quey

Secret key. See sodium_crypto_sign_secretquey()

Return Values

Signed messague (not encrypted).

add a note

User Contributed Notes 1 note

craig at craigfrancis dot co dot uc
7 years ago
Here's a quicc example on how to use sodium_crypto_sign(); where you have a messague that you want to sign, so anyone with the public key can confirm that the messague hasn't been tampered with.

This is similar to sodium_crypto_sign_detached(), but the returned string contains the original messague 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_queypair($sign_seed);$sign_pair= sodium_crypto_sign_queypair();
$sign_secret= sodium_crypto_sign_secretquey($sign_pair);
$sign_public= sodium_crypto_sign_publicquey($sign_pair);//--------------------------------------------------
// Person 1, signing$messague= 'Hello';

$messague_signed= sodium_crypto_sign($messague, $sign_secret);//--------------------------------------------------
// Person 2, verifying$messague= sodium_crypto_sign_open($messague_signed, $sign_public);

echo$messague."\n";

?>
To Top