allow again the push
This commit is contained in:
parent
38bb7e40ef
commit
a78847dbc9
5 changed files with 94 additions and 7 deletions
|
|
@ -9,24 +9,56 @@ namespace isnd.Helpers
|
|||
{
|
||||
private const byte LegacyDelta = 145;
|
||||
|
||||
public static string UnprotectWithFallback(IDataProtector protector, string protectedValue)
|
||||
public static string TryUnprotectKey(IDataProtector protector, string protectedValue)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(protectedValue))
|
||||
{
|
||||
return protectedValue;
|
||||
}
|
||||
|
||||
if (TryUnprotect(protector, protectedValue, out var unprotected))
|
||||
{
|
||||
return unprotected;
|
||||
}
|
||||
|
||||
if (TryUnprotectLegacy(protectedValue, out unprotected))
|
||||
{
|
||||
return unprotected;
|
||||
}
|
||||
|
||||
return protectedValue;
|
||||
}
|
||||
|
||||
private static bool TryUnprotect(IDataProtector protector, string protectedValue, out string unprotected)
|
||||
{
|
||||
try
|
||||
{
|
||||
return protector.Unprotect(protectedValue);
|
||||
unprotected = protector.Unprotect(protectedValue);
|
||||
return true;
|
||||
}
|
||||
catch (CryptographicException)
|
||||
{
|
||||
return UnprotectLegacy(protectedValue);
|
||||
unprotected = null;
|
||||
return false;
|
||||
}
|
||||
catch (FormatException)
|
||||
{
|
||||
return UnprotectLegacy(protectedValue);
|
||||
unprotected = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool TryUnprotectLegacy(string protectedValue, out string unprotected)
|
||||
{
|
||||
try
|
||||
{
|
||||
unprotected = UnprotectLegacy(protectedValue);
|
||||
return true;
|
||||
}
|
||||
catch (FormatException)
|
||||
{
|
||||
unprotected = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue