This commit is contained in:
Saufi
2026-06-03 08:51:22 +08:00
commit a14d43fe34
347 changed files with 38197 additions and 0 deletions

View File

@@ -0,0 +1,54 @@
<?php
namespace App\Support;
class SensitiveData
{
public static function maskIc(?string $value): string
{
return self::mask($value, 4, 4);
}
public static function maskAccount(?string $value): string
{
return self::mask($value, 3, 4);
}
public static function maskPhone(?string $value): string
{
return self::mask($value, 3, 3);
}
public static function maskName(?string $value): string
{
$normalized = trim((string) $value);
if ($normalized === '') {
return '-';
}
$length = mb_strlen($normalized);
$visible = min(3, $length);
return mb_substr($normalized, 0, $visible).str_repeat('*', max(0, $length - $visible));
}
private static function mask(?string $value, int $prefix, int $suffix): string
{
$normalized = trim((string) $value);
if ($normalized === '') {
return '-';
}
$length = mb_strlen($normalized);
if ($length <= ($prefix + $suffix)) {
return str_repeat('*', $length);
}
return mb_substr($normalized, 0, $prefix)
.str_repeat('*', $length - $prefix - $suffix)
.mb_substr($normalized, -$suffix);
}
}