PHP code example of virgil / crypto

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

    

virgil / crypto example snippets


$crypto = new VirgilCrypto();
$keyPair = $crypto->generateKeyPair();

$crypto = new VirgilCrypto();
$senderKeyPair = $crypto->generateKeyPair();

// prepare a message
$messageToSign = "Hello, Bob!";

// generate a signature
$signature = $crypto->generateSignature($messageToSign, $senderKeyPair->getPrivateKey());

$crypto = new VirgilCrypto();
    
$senderKeyPair = $crypto->generateKeyPair();    
    
// prepare a message
$messageToSign = "Hello, Bob!";

// generate a signature
$signature = $crypto->generateSignature($messageToSign, $senderKeyPair->getPrivateKey());
    
// verify a signature
$verified = $crypto->verifySignature($signature, $messageToSign, $senderKeyPair->getPublicKey());

$crypto = new VirgilCrypto();
$receiverKeyPair = $crypto->generateKeyPair();

// prepare a message
$messageToEncrypt = "Hello, Bob!";

// encrypt the message
$encryptedData = $crypto->encrypt($messageToEncrypt, new VirgilPublicKeyCollection($receiverKeyPair->getPublicKey()));

$crypto = new VirgilCrypto();
$receiverKeyPair = $crypto->generateKeyPair();

// prepare a message
$messageToEncrypt = "Hello, Bob!";

// encrypt the message
$encryptedData = $crypto->encrypt($messageToEncrypt, new VirgilPublicKeyCollection($receiverKeyPair->getPublicKey()));

// prepare data to be decrypted and decrypt the encrypted data using a private key
$decryptedData = $crypto->decrypt($encryptedData, $receiverKeyPair->getPrivateKey());