feat: core utilities - CSRF, auth, encryption, PHPMailer
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
17
includes/encryption.php
Normal file
17
includes/encryption.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?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);
|
||||
}
|
||||
Reference in New Issue
Block a user