sodium_crypto_secretbox

(PHP 7 >= 7.2.0)

sodium_crypto_secretboxEncrypt a message

Opis

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

Ostrzeżenie

Ta funkcja jest obecnie nieudokumentowana, dostępna jest jedynie lista jej argumentów.

Parametry

string

nonce

key

Zwracane wartości

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