sodium_crypto_box_seal

(PHP 7 >= 7.2.0)

sodium_crypto_box_sealEncrypt a message

说明

string sodium_crypto_box_seal ( string $msg , string $key )

Warning

本函数还未编写文档,仅有参数列表。

参数

msg

key

返回值

add a note add a note

User Contributed Notes 1 note

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