Created
December 12, 2018 21:49
-
-
Save johnallers/a3155b808ff495505bcb712fe4fda0f5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://tools.ietf.org/html/rfc4648#section-5 | |
public class Base64Url | |
{ | |
public static string Encode(byte[] inArray) | |
{ | |
var base64 = Convert.ToBase64String(inArray); | |
return base64 | |
.Replace("+", "-") | |
.Replace("/", "_") | |
.Replace("=", ""); | |
} | |
public static byte[] Decode(string s) | |
{ | |
var sb = new StringBuilder(s); | |
sb.Replace("-", "+"); | |
sb.Replace("_", "/"); | |
while (sb.Length * 6 % 8 != 0) | |
{ | |
sb.Append("="); | |
} | |
return Convert.FromBase64String(sb.ToString()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment