note 128306 added to function.sodium-crypto-aead-chacha20poly1305-encrypt

From: Date: Mon, 13 Mar 2023 06:30:33 +0000
Subject: note 128306 added to function.sodium-crypto-aead-chacha20poly1305-encrypt
Groups: php.notes 
Request: Send a blank email to php-notes+get-220263@lists.php.net to get a copy of this message
A flip/flop unit test to give you a sample: <?php use PHPUnit\Framework\TestCase; class SodiumTest extends TestCase { public function testSodium() { // or 32 cryptographically secure bytes // store the key securely with other secrets in your app $key = sodium_crypto_aead_xchacha20poly1305_ietf_keygen(); // 8-bytes nonce should be stored along with the ciphertext (will be needed for decryption) // It is not sensitive, you may just prepend it before the ciphertext. $nonce = random_bytes(SODIUM_CRYPTO_AEAD_CHACHA20POLY1305_NPUBBYTES); $flip = 'Hello, world!'; $ciphertext = sodium_crypto_aead_chacha20poly1305_encrypt($flip, $nonce, $nonce, $key); $flop = sodium_crypto_aead_chacha20poly1305_decrypt($ciphertext, $nonce, $nonce, $key); $this->assertEquals($flip, $flop); } } ?> Side note: the nonce is used twice in this test, but you can use a username, an identifier or whatever you like in $additional_data ---- Server IP: 45.112.84.4 Probable Submitter: 80.90.13.130 (proxied: 169.155.255.33) ---- Manual Page -- https://php.net/manual/en/function.sodium-crypto-aead-chacha20poly1305-encrypt.php Edit -- https://main.php.net/note/edit/128306 Del: integrated -- https://main.php.net/note/delete/128306/integrated Del: useless -- https://main.php.net/note/delete/128306/useless Del: bad code -- https://main.php.net/note/delete/128306/bad+code Del: spam -- https://main.php.net/note/delete/128306/spam Del: non-english -- https://main.php.net/note/delete/128306/non-english Del: in docs -- https://main.php.net/note/delete/128306/in+docs Del: other reasons-- https://main.php.net/note/delete/128306 Reject -- https://main.php.net/note/reject/128306 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#220263) next »