PHP code example of spaze / encryption
1. Go to this page and download the library: Download spaze/encryption 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/ */
spaze / encryption example snippets
Spaze\Encryption\SymmetricKeyEncryption::__construct(array $keys, string $activeKeyId, string $keyPrefix)
$keys = [
'key1' => 'adek_79e0[...]8a8d',
'key2' => 'adek_d22c[...]cfa3',
];
$activeKeyId = 'key2';
$keyPrefix = 'adek';
$encryption = new Spaze\Encryption\SymmetricKeyEncryption($keys, $activeKeyId, $keyPrefix);
Spaze\Encryption\SymmetricKeyEncryption::encrypt(string $data): string
$encrypted = $encryption->encrypt($addressData);
Spaze\Encryption\SymmetricKeyEncryption::encryptWithAd(string $data, string $additionalData): string
$encrypted = $encryption->encryptWithAd($addressData, $tenantId);
Spaze\Encryption\SymmetricKeyEncryption::decrypt(string $data): string
$decrypted = $encryption->decrypt($encrypted);
Spaze\Encryption\SymmetricKeyEncryption::decryptWithAd(string $data, string $additionalData): string
$decrypted = $encryption->decryptWithAd($encrypted, $tenantId);
bin2hex(random_bytes(32))
use Spaze\Encryption\SymmetricKeyEncryption;
class Something
{
public function __construct(
private SymmetricKeyEncryption $emailEncryption,
) {
// ...
}
public function doSomething()
{
// ...
$encryptedEmail = $this->emailEncryption->encrypt($email);
// ...
}
public function doSomethingElse()
{
// ...
$decryptedEmail = $this->emailEncryption->decrypt($email);
// ...
}
}