Skip to content

Instantly share code, notes, and snippets.

View alexc-hollywood's full-sized avatar

AC alexc-hollywood

  • Los Angeles, CA
View GitHub Profile
@alexc-hollywood
alexc-hollywood / libsodium.php
Created May 25, 2023 22:44
Encrypt/decrypt with libsodium
<?php
function encrypt (string $message, string $key) : array
{
$nonce = random_bytes (SODIUM_CRYPTO_SECRETBOX_NONCEBYTES);
$ciphertext = sodium_crypto_secretbox ($message, $nonce, base64_decode ($key));
return [
'nonce' => base64_encode ($nonce),