Class SensitiveMasker
敏感值脱敏器
public class SensitiveMasker : IValueMasker
- Inheritance
-
SensitiveMasker
- Implements
- Inherited Members
Remarks
性能优化:
- 使用 Lazy 延迟编译正则表达式
- 使用 RegexOptions.Compiled 提升匹配性能
- 简单模式使用 string.Contains 快速路径
- 缓存 ShouldMask 结果
- 使用 string.Create 减少字符串分配
Constructors
SensitiveMasker(MaskingOptions?)
初始化敏感值脱敏器
public SensitiveMasker(MaskingOptions? options = null)
Parameters
optionsMaskingOptions脱敏选项,为 null 时使用默认选项
Methods
ClearCache()
清除 ShouldMask 缓存
public void ClearCache()
Mask(string, string?)
脱敏处理
public string Mask(string key, string? value)
Parameters
Returns
- string
脱敏后的值
ShouldMask(string)
判断是否应该脱敏该键
public bool ShouldMask(string key)
Parameters
keystring配置键
Returns
- bool
如果应该脱敏返回 true,否则返回 false