Update -> refactor and optimize UI , code ,...
This commit is contained in:
@@ -1,15 +1,32 @@
|
||||
<?php
|
||||
function encryptText($text, $key) {
|
||||
$iv = random_bytes(16);
|
||||
|
||||
function encryptText(string $text, string $key): array
|
||||
{
|
||||
$iv = random_bytes(16);
|
||||
$cipher = openssl_encrypt($text, 'AES-256-CBC', $key, 0, $iv);
|
||||
if ($cipher === false) {
|
||||
throw new RuntimeException('Encryption failed.');
|
||||
}
|
||||
return [
|
||||
'cipher' => $cipher,
|
||||
'iv' => base64_encode($iv)
|
||||
'iv' => base64_encode($iv),
|
||||
];
|
||||
}
|
||||
function decryptText($cipher, $iv, $key) {
|
||||
|
||||
function decryptText(string $cipher, string $iv, string $key): string|false
|
||||
{
|
||||
return openssl_decrypt($cipher, 'AES-256-CBC', $key, 0, base64_decode($iv));
|
||||
}
|
||||
function generateId() {
|
||||
|
||||
function generateId(): string
|
||||
{
|
||||
return bin2hex(random_bytes(16));
|
||||
}
|
||||
|
||||
function jsonResponse(array $data, int $status = 200): void
|
||||
{
|
||||
http_response_code($status);
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode($data);
|
||||
exit;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user