ajout calendrier ios
Deploy HouseHub / deploy (push) Successful in 2s

This commit is contained in:
Cedric
2026-05-13 14:00:29 +02:00
parent 63833abbc7
commit 1c274289bf
19 changed files with 881 additions and 6 deletions
+35
View File
@@ -0,0 +1,35 @@
<?php
function hh_encrypt_secret(string $plain): string
{
$keyMaterial = getenv('APP_SECRET_KEY') ?: '';
if ($keyMaterial === '') {
throw new RuntimeException('APP_SECRET_KEY manquant');
}
$key = hash('sha256', $keyMaterial, true);
$iv = random_bytes(16);
$cipher = openssl_encrypt($plain, 'AES-256-CBC', $key, OPENSSL_RAW_DATA, $iv);
if ($cipher === false) {
throw new RuntimeException('Chiffrement impossible');
}
return base64_encode($iv . $cipher);
}
function hh_decrypt_secret(string $encrypted): string
{
$keyMaterial = getenv('APP_SECRET_KEY') ?: '';
if ($keyMaterial === '') {
throw new RuntimeException('APP_SECRET_KEY manquant');
}
$raw = base64_decode($encrypted, true);
if ($raw === false || strlen($raw) <= 16) {
throw new RuntimeException('Secret invalide');
}
$key = hash('sha256', $keyMaterial, true);
$iv = substr($raw, 0, 16);
$cipher = substr($raw, 16);
$plain = openssl_decrypt($cipher, 'AES-256-CBC', $key, OPENSSL_RAW_DATA, $iv);
if ($plain === false) {
throw new RuntimeException('Déchiffrement impossible');
}
return $plain;
}