28 lines
671 B
PHP
28 lines
671 B
PHP
<?php
|
|
|
|
function encrypt_id($id)
|
|
{
|
|
$key = 'SN28062003';
|
|
$encrypted = openssl_encrypt((string) $id, 'AES-128-ECB', $key, OPENSSL_RAW_DATA);
|
|
|
|
if ($encrypted === false) {
|
|
return '';
|
|
}
|
|
|
|
return rtrim(strtr(base64_encode($encrypted), '+/', '-_'), '=');
|
|
}
|
|
|
|
function decrypt_id($encrypted)
|
|
{
|
|
$key = 'SN28062003';
|
|
$decoded = base64_decode(strtr((string) $encrypted, '-_', '+/') . str_repeat('=', (4 - strlen((string) $encrypted) % 4) % 4), true);
|
|
|
|
if ($decoded === false) {
|
|
return null;
|
|
}
|
|
|
|
$decrypted = openssl_decrypt($decoded, 'AES-128-ECB', $key, OPENSSL_RAW_DATA);
|
|
|
|
return $decrypted === false ? null : $decrypted;
|
|
}
|