PHP code example of michaelmawhinney / cryptex
1. Go to this page and download the library: Download michaelmawhinney/cryptex library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
michaelmawhinney / cryptex example snippets
declare(strict_types=1);
te this once and store it in a secret manager or equivalent protected store.
$key = sodium_bin2hex(
random_bytes(SODIUM_CRYPTO_AEAD_XCHACHA20POLY1305_IETF_KEYBYTES)
);
$plaintext = "You're a certified prince.";
$salt = Cryptex::generateSalt();
$ciphertext = Cryptex::encrypt($plaintext, $key, $salt);
$decrypted = Cryptex::decrypt($ciphertext, $key, $salt);
if (!hash_equals($plaintext, $decrypted)) {
throw new RuntimeException('Round trip failed.');
}