feat: update auth and security flow

This commit is contained in:
taekyoungc
2026-04-08 00:23:21 +09:00
parent b5eed31b94
commit 06fedc866a
7 changed files with 75 additions and 35 deletions

View File

@@ -8,6 +8,7 @@ declare(strict_types=1);
*
* 저장 형식: 암호화된 값은 "ENC:" + base64(암호문) 으로 저장. "ENC:" 없으면 평문(기존)으로 간주.
*/
if (! function_exists('pii_encrypt')) {
function pii_encrypt(?string $value): string
{
@@ -21,9 +22,8 @@ if (! function_exists('pii_encrypt')) {
}
$encrypter = service('encrypter');
$encrypted = $encrypter->encrypt($value);
return 'ENC:' . base64_encode($encrypted);
} catch (Throwable) {
} catch (Throwable $e) {
return $value;
}
}
@@ -44,13 +44,23 @@ if (! function_exists('pii_decrypt')) {
return $value;
}
$encrypter = service('encrypter');
$raw = base64_decode(substr($value, 4), true);
if ($raw === false) {
return $value;
$payload = substr($value, 4);
// 현재 포맷: ENC: + base64(raw ciphertext)
$raw = base64_decode($payload, true);
if ($raw !== false) {
try {
return $encrypter->decrypt($raw);
} catch (Throwable $e) {
// legacy 포맷 재시도
}
}
return $encrypter->decrypt($raw);
} catch (Throwable) {
// 레거시 포맷 호환:
// - ENC: + encrypter 반환값(rawData=false 환경 등) 또는
// - ENC: + 기타 문자열 포맷
return $encrypter->decrypt($payload);
} catch (Throwable $e) {
return $value;
}
}