libsodium-php icon indicating copy to clipboard operation
libsodium-php copied to clipboard

crypt & decrypt with libsodium

Open gtraxx opened this issue 3 years ago • 0 comments

Hello, Unable to use libsodium it returns me characters unrelated to the original key

$secretKey = sodium_crypto_secretbox_keygen();
$message = 'Sensitive information';
$blockSize = 16;

$nonce = random_bytes(SODIUM_CRYPTO_SECRETBOX_NONCEBYTES);
$paddedMessage = sodium_pad($message, $blockSize);
$encryptedMessage = sodium_crypto_secretbox($paddedMessage, $nonce, $secretKey);
$decryptedPaddedMessage = sodium_crypto_secretbox_open($encryptedMessage, $nonce, $secretKey);
$decryptedMessage = sodium_unpad($decryptedPaddedMessage, $blockSize);

print $decryptedMessage;
Capture d’écran 2022-06-16 à 17 35 50

I am looking for a way to encrypt a string of characters and then to be able to decrypt it

Best Regards Aurelien

gtraxx avatar Jun 16 '22 15:06 gtraxx