Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
Base64Url.cs
1using System;
2
3namespace Waher.Content
4{
10 public static class Base64Url
11 {
17 public static byte[] Decode(string Base64Url)
18 {
19 int c = Base64Url.Length;
20 int i = c & 3;
21
22 Base64Url = Base64Url.Replace('-', '+'); // 62nd char of encoding
23 Base64Url = Base64Url.Replace('_', '/'); // 63rd char of encoding
24
25 switch (i)
26 {
27 case 1:
28 Base64Url += "A==";
29 break;
30
31 case 2:
32 Base64Url += "==";
33 break;
34
35 case 3:
36 Base64Url += "=";
37 break;
38 }
39
40 return Convert.FromBase64String(Base64Url);
41 }
42
48 public static string Encode(byte[] Data)
49 {
50 string s = Convert.ToBase64String(Data);
51 int c = Data.Length;
52 int i = c % 3;
53
54 if (i == 1)
55 s = s.Substring(0, s.Length - 2);
56 else if (i == 2)
57 s = s.Substring(0, s.Length - 1);
58
59 s = s.Replace('+', '-'); // 62nd char of encoding
60 s = s.Replace('/', '_'); // 63rd char of encoding
61
62 return s;
63 }
64 }
65}
Static class that does BASE64URL encoding (using URL and filename safe alphabet), as defined in RFC46...
Definition: Base64Url.cs:11
static string Encode(byte[] Data)
Converts a binary block of data to a Base64URL-encoded string.
Definition: Base64Url.cs:48
static byte[] Decode(string Base64Url)
Converts a Base64URL-encoded string to its binary representation.
Definition: Base64Url.cs:17