parent root
PHP: sodium_crypto_box_seal - Manual

sodium_crypto_box_seal

(PHP 7 >= 7.2.0)

sodium_crypto_box_sealEncrypt a message

Description

sodium_crypto_box_seal ( string $msg , string $key ) : string

Warning

This function is currently not documented; only its argument list is available.

Parameters

msg

key

Return Values

add a noteadd a note

User Contributed Notes 1 note

up
2
craig at craigfrancis dot co dot uk
1 year 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
parent root