ow
This commit is contained in:
1 parent
3461a2e921
commit
ddfbd7d0f2
17 files changed
+523
-241
No files matched your search
@@ -67,7 +67,7 @@ namespace CloudBuilder.Security.Service
|
||||
if (current is byte[]) return; // already decoded by the converter
|
||||
if (current is string s && !string.IsNullOrEmpty(s))
|
||||
{
|
||||
try { prop.SetValue(target, Fido2NetLib.Base64Url.Decode(s)); }
|
||||
try { prop.SetValue(target, MyBase64Url.Decode(s)); }
|
||||
catch { /* leave original value; Fido2NetLib will surface a clearer error */ }
|
||||
}
|
||||
return;
|
||||
@@ -78,7 +78,7 @@ namespace CloudBuilder.Security.Service
|
||||
{
|
||||
if (current is string s && !string.IsNullOrEmpty(s))
|
||||
{
|
||||
try { prop.SetValue(target, Fido2NetLib.Base64Url.Decode(s)); } catch { }
|
||||
try { prop.SetValue(target, MyBase64Url.Decode(s)); } catch { }
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -89,4 +89,34 @@ namespace CloudBuilder.Security.Service
|
||||
// InvalidCastException that we can diagnose from the stack trace.
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 跨平台 Base64Url,行为等价旧Fido2NetLib.Base64Url,Windows+Linux完全兼容
|
||||
/// </summary>
|
||||
public static class MyBase64Url
|
||||
{
|
||||
public static byte[] Decode(string input)
|
||||
{
|
||||
if (string.IsNullOrEmpty(input))
|
||||
return null;
|
||||
|
||||
// base64url → 标准base64
|
||||
input = input.Replace('-', '+').Replace('_', '/');
|
||||
switch (input.Length % 4)
|
||||
{
|
||||
case 2: input += "=="; break;
|
||||
case 3: input += "="; break;
|
||||
}
|
||||
return Convert.FromBase64String(input);
|
||||
}
|
||||
|
||||
public static string Encode(byte[] data)
|
||||
{
|
||||
if (data == null) return null;
|
||||
return Convert.ToBase64String(data)
|
||||
.Replace('+', '-')
|
||||
.Replace('/', '_')
|
||||
.TrimEnd('=');
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user