Files
gestoria-lp/includes/encryption.php
2026-03-01 23:28:54 +00:00

18 lines
603 B
PHP

<?php
require_once __DIR__ . '/config.php';
function encryptData(string $plaintext): string {
$iv = random_bytes(16);
$key = hash('sha256', ENCRYPTION_KEY, true);
$encrypted = openssl_encrypt($plaintext, 'aes-256-cbc', $key, OPENSSL_RAW_DATA, $iv);
return base64_encode($iv . $encrypted);
}
function decryptData(string $ciphertext): string {
$data = base64_decode($ciphertext);
$iv = substr($data, 0, 16);
$encrypted = substr($data, 16);
$key = hash('sha256', ENCRYPTION_KEY, true);
return openssl_decrypt($encrypted, 'aes-256-cbc', $key, OPENSSL_RAW_DATA, $iv);
}