PHP code example of ramazancetinkaya / obscura
1. Go to this page and download the library: Download ramazancetinkaya/obscura 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/ */
ramazancetinkaya / obscura example snippets
amazancetinkaya\Obscura;
use ramazancetinkaya\ObscuraException;
try {
// Create an Obscura instance
$secretKey = 'my-super-secure-key';
$obscura = new Obscura($secretKey);
// Data to encrypt
$plainText = 'Hello World!';
// Encrypt
$encrypted = $obscura->encrypt($plainText);
echo "Encrypted (base64): " . $encrypted . PHP_EOL;
// Decrypt
$decrypted = $obscura->decrypt($encrypted);
echo "Decrypted: " . $decrypted . PHP_EOL;
} catch (ObscuraException $e) {
echo "Error: " . $e->getMessage();
}
amazancetinkaya\Obscura;
use ramazancetinkaya\ObscuraException;
try {
// URL-safe Obscura instance
$secretKey = 'my-super-secure-key';
$obscuraSafe = new Obscura($secretKey, 'aes-256-cbc', true);
// Data to encrypt
$plainUrl = 'https://example.com?param=someValue';
// Encrypt (URL-safe)
$encryptedUrl = $obscuraSafe->encrypt($plainUrl);
echo "Encrypted (URL-safe): " . $encryptedUrl . PHP_EOL;
// Decrypt
$decryptedUrl = $obscuraSafe->decrypt($encryptedUrl);
echo "Decrypted URL: " . $decryptedUrl . PHP_EOL;
} catch (ObscuraException $e) {
echo "Error: " . $e->getMessage();
}