sodium_crypto_box_seal

(PHP 7 >= 7.2.0)

sodium_crypto_box_sealEncrypt a message

Descrierea

sodium_crypto_box_seal ( string $message , string $key_pair ) : string

Avertizare

Această funcție nu este documentată în prezent; este disponibilă numai lista sa de argumente.

Parametri

message

key_pair

Valorile întoarse

add a note add a note

User Contributed Notes 1 note

up
9
craig at craigfrancis dot co dot uk
6 years ago
Here's a quick example on how to use sodium_crypto_box_seal(); where you have 2 people exchanging a $message - person 1 encrypts it so that only person 2 can decrypt it. It does not allow person 2 to know who sent it, as only their public key way used (see sodium_crypto_box to do that).

<?php

$keypair
= sodium_crypto_box_keypair();
$keypair_public = sodium_crypto_box_publickey($keypair);
$keypair_secret = sodium_crypto_box_secretkey($keypair);

// $key_public = sodium_crypto_box_publickey_from_secretkey($keypair_secret);
// $keypair = sodium_crypto_box_keypair_from_secretkey_and_publickey($keypair_secret, $key_public);

//--------------------------------------------------
// Person 1, encrypting

$message = 'hello';

$encrypted = sodium_crypto_box_seal($message, $keypair_public);

echo
base64_encode($encrypted) . "\n";

//--------------------------------------------------
// Person 2, decrypting

$decrypted = sodium_crypto_box_seal_open($encrypted, $keypair);

echo
$decrypted . "\n";

?>
To Top