Skip to content

Instantly share code, notes, and snippets.

View DimDev's full-sized avatar

Dzmitry Kazbiarovich DimDev

  • EPAM Systems
  • Wrocław, Poland
View GitHub Profile
@DimDev
DimDev / sodium_example.php
Created April 2, 2021 12:21
PHP Sodium encryption example
<?php
$msg = 'This is a super secret message!';
// Generating an encryption key and a nonce
$key = random_bytes(SODIUM_CRYPTO_SECRETBOX_KEYBYTES); // 256 bit
$nonce = random_bytes(SODIUM_CRYPTO_SECRETBOX_NONCEBYTES); // 24 bytes
// Encrypt
$ciphertext = sodium_crypto_secretbox($msg, $nonce, $key);
// Decrypt
w - move cursor to the beginning of the next word
e - move cursor to the end of the next word
) - move cursor to the beginning of the next sentence
( - move cursor to the beginning of the previous sentence
} - move cursor to the beginning of the next paragraph
{ - move cursor to the beginning of the previous paragraph
/somsething<ENTER> - search for "something", press "n" key to move next