private static bool IsParamNeedUnprotect(this ParamsProtectionOptions option, string propName, string value) { if (option.ProtectParams.Any(p => p.Equals(propName, StringComparison.OrdinalIgnoreCase))) { return(!option.ParamValueProtectFuncEnabled || !option.ParamValueNeedProtectFunc(value)); } return(false); }
public ParamsProtectionResourceFilter(IDataProtectionProvider protectionProvider, ILogger <ParamsProtectionResourceFilter> logger, IOptions <ParamsProtectionOptions> options) { _option = options.Value; _protector = protectionProvider.CreateProtector(_option.ProtectorPurpose ?? ParamsProtectionHelper.DefaultPurpose); if (_option.ExpiresIn.GetValueOrDefault(0) > 0) { _protector = _protector.ToTimeLimitedDataProtector(); } _logger = logger; }
private static void ProtectParams(JToken token, ITimeLimitedDataProtector protector, ParamsProtectionOptions option) { if (token is JArray array) { foreach (var j in array) { if (array.Parent is JProperty property && j is JValue val) { var strJ = val.Value.ToString(); if (option.IsParamNeedProtect(property.Name, strJ)) { val.Value = protector.Protect(strJ, TimeSpan.FromMinutes(option.ExpiresIn.GetValueOrDefault(10))); } } else { ProtectParams(j, protector, option); } }
private static bool IsParamValueNeedProtect(this ParamsProtectionOptions option, string value) { return(!option.ParamValueProtectFuncEnabled || option.ParamValueNeedProtectFunc(value)); }