PHP code example of irfan-manitechnest / sodium-crypto

1. Go to this page and download the library: Download irfan-manitechnest/sodium-crypto 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/ */

    

irfan-manitechnest / sodium-crypto example snippets


use SodiumCrypto\Crypto\FideliusEncryptor;

$keys = FideliusEncryptor::generateKeyPair();

echo "Public Key: " . $keys['publicKey'] . PHP_EOL;
echo "Private Key: " . $keys['privateKey'] . PHP_EOL;

use SodiumCrypto\Crypto\FideliusEncryptor;

// Sender encrypts
$encrypted = FideliusEncryptor::encrypt(
    "Hello Secure World",
    $senderPrivateKey,
    $senderPublicKey,      // Sender's public key
    $recipientPublicKey    // Recipient's public key
);

// Recipient decrypts
$decrypted = FideliusEncryptor::decrypt(
    $encrypted['ciphertext'],
    $encrypted['nonce'],
    $recipientPrivateKey,
    $encrypted['keyToShare'] // Sender's public key
);

use SodiumCrypto\Crypto\Encryptor;

$key = Encryptor::generateKey();
$cipher = Encryptor::encrypt("Secret Message", $key);
$plain  = Encryptor::decrypt($cipher, $key);

use SodiumCrypto\Crypto\Signer;

$signKeys = Signer::generateKeyPair();
$signature = Signer::sign("Important data", $signKeys['privateKey']);

$isValid = Signer::verify("Important data", $signature, $signKeys['publicKey']);

use SodiumCrypto\Crypto\PasswordEncryptor;

$hash = PasswordEncryptor::hashPassword("SuperSecret");
$isValid = PasswordEncryptor::verifyPassword("SuperSecret", $hash);

src/
  Crypto/
    Encryptor.php
    FideliusEncryptor.php
    KeyManager.php
    Signer.php
    PasswordEncryptor.php
    Utils.php
  Exception/
    *.php
tests/
  Crypto/
    *.php
phpunit.xml
composer.json