-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathBase64Encoder.cs
More file actions
28 lines (22 loc) · 1.13 KB
/
Copy pathBase64Encoder.cs
File metadata and controls
28 lines (22 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
namespace Exyll;
/// <remarks>Based on http://www.csharp411.com/convert-binary-to-base64-string/</remarks>
public class Base64Encoder : BaseEncoder
{
const string CharacterSetBase = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
public readonly char PlusChar;
public readonly char SlashChar;
public static readonly Base64Encoder Default = new('+', '/', true);
public static readonly Base64Encoder DefaultNoPadding = new('+', '/', false);
public static readonly Base64Encoder UrlEncoding = new('-', '_', false);
public static readonly Base64Encoder XmlEncoding = new('_', ':', false);
public static readonly Base64Encoder RegExEncoding = new('!', '-', false);
public static readonly Base64Encoder FileEncoding = new('+', '-', false);
public Base64Encoder(char plusChar, char slashChar, bool paddingEnabled)
: base((CharacterSetBase + plusChar + slashChar).ToCharArray(), paddingEnabled)
{
PlusChar = plusChar;
SlashChar = slashChar;
}
public static byte[] FromBase64String(string data) => Default.FromBase(data);
public static string ToBase64String(byte[] data) => Default.ToBase(data);
}