Verschlüsselung

Um sodium zu aktivieren, muss in der php.ini die Zeile extension=sodium eingefügt werden. Darüber hinaus, muss die Datei php\libsodium.dll in das Verzeichnis apache\bin kopiert werden. Server neu starten und phpinfo() sollte sodium anzeigen.

Beispielcode:

<?php

$secret_key = sodium_crypto_secretbox_keygen();
$message = 'Geheime Informationen';

$nonce = random_bytes(SODIUM_CRYPTO_SECRETBOX_NONCEBYTES);
$encrypted_message = sodium_crypto_secretbox($message, $nonce, $secret_key);

echo $encrypted_message;

echo "<br>";

$decrypted_message = sodium_crypto_secretbox_open($encrypted_message, $nonce, $secret_key);
echo $decrypted_message;