try {
$symmetric = newSymmetricEncryption();
$encrypted = /* get encrypted data from database */;
$iv = /* get iv from database */;
$decrypted = $symmetric->decrypt($encrypted, 'MyPassphrase', $iv);
} catch (EncryptionException$e) {
echo"Something went wrong...";
}
Asymetric encryption
Generate private/public key pair
try {
$asymmetric = newAsymmetricEncryption();
$publicKey = $asymmetric->getPublicKey(); // or export to a file$privateKey = $asymmetric->getPrivateKey('MyPassphrase'); // or export to a file$encrypted = $asymmetric->encrypt('String to encrypt', $publicKey);
} catch (EncryptionException$e) {
echo"Something went wrong...";
}
Decrypt with private key
try {
$asymmetric = newAsymmetricEncryption();
$privateKey = /* get private key */;
$encrypted = /* get encrypted data */;
$decrypted = $asymmetric->decrypt($encrypted, $privateKey, 'MyPassphrase');
} catch (EncryptionException$e) {
echo"Something went wrong...";
}