Update Banyak
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
// encrypt url
|
||||
define('ENCRYPTION_KEY', hex2bin('9a307dfcf16ac2e4406b1a59a31c1d096eafe37e40c60ddee4bb827b6a947079'));
|
||||
define('ENCRYPTION_METHOD', 'AES-256-CBC');
|
||||
|
||||
function encrypt_url($data) {
|
||||
$iv = random_bytes(16);
|
||||
$encrypted = openssl_encrypt($data, ENCRYPTION_METHOD, ENCRYPTION_KEY, OPENSSL_RAW_DATA, $iv);
|
||||
// Gabungkan IV hex + "::" + encrypted base64, lalu base64 encode seluruh string
|
||||
$result = base64_encode(bin2hex($iv) . "::" . base64_encode($encrypted));
|
||||
return $result;
|
||||
}
|
||||
|
||||
function decrypt_url($data) {
|
||||
$decoded = base64_decode($data);
|
||||
if ($decoded === false) return false;
|
||||
$parts = explode('::', $decoded);
|
||||
if (count($parts) !== 2) return false;
|
||||
|
||||
$iv = hex2bin($parts[0]);
|
||||
$encrypted_data = base64_decode($parts[1]);
|
||||
return openssl_decrypt($encrypted_data, ENCRYPTION_METHOD, ENCRYPTION_KEY, OPENSSL_RAW_DATA, $iv);
|
||||
}
|
||||
Reference in New Issue
Block a user