PHP code example of asymmetricrypt / asymmetricrypt
1. Go to this page and download the library: Download asymmetricrypt/asymmetricrypt 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/ */
asymmetricrypt / asymmetricrypt example snippets
use AsymmetriCrypt\Crypter;
use AsymmetriCrypt\Key\PublicKey;
use AsymmetriCrypt\Key\PrivateKey;
// Create a private key
$priv = Crypter::createPrivateKey();
// or
$priv = PrivateKey::create();
// Load a private key
$priv = Crypter::loadPrivateKey("file:///path/to/key.pem");
// or
$priv = new PrivateKey("file:///path/to/key.pem");
// Get derived public key
$pub = $priv->getPublicKey();
// Load a public key
$pub = Crypter::loadPublicKey("file:///path/to/key.pub");
// or
$pub = new PublicKey("file:///path/to/key.pub");
// Encrypt data
$encrypted = Crypter::encrypt("data to encrypt", $pub);
// Decrypt data
$decrypted = Crypter::decrypt($encrypted, $priv);
// Sign data
$signature = Crypter::sign("data to sign", $priv);
// Verify signature
$signature_valid = Crypter::verify("data to sign", $signature, $pub);