sodium_crypto_secretbox

(PHP 7 >= 7.2.0)

sodium_crypto_secretboxEncrypt a message

Descrierea

sodium_crypto_secretbox ( string $message , string $nonce , string $key ) : string

Avertizare

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

Parametri

message

nonce

key

Valorile întoarse

add a note add a note

User Contributed Notes 1 note

up
1
celso fontes
3 years ago
An example to how encrypt or decrypt using sodium:

<?php

$key
= random_bytes(SODIUM_CRYPTO_SECRETBOX_KEYBYTES);

$nonce = random_bytes(SODIUM_CRYPTO_SECRETBOX_NONCEBYTES);
$ciphertext = sodium_crypto_secretbox("Hello World !", $nonce, $key);

$plaintext = sodium_crypto_secretbox_open($ciphertext, $nonce, $key);
if (
$plaintext === false) {
    throw new
Exception("Bad ciphertext");
}

echo
$plaintext;
To Top