Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- byte[] bytes = Convert.FromBase64String(cipherText);
- public static class Base64Helper
- {
- public static byte[] TryParse(string s)
- {
- if (s == null) throw new ArgumentNullException("s");
- if ((s.Length % 4 == 0) && _rx.IsMatch(s))
- {
- try
- {
- return Convert.FromBase64String(s);
- }
- catch (FormatException)
- {
- // ignore
- }
- }
- return null;
- }
- private static readonly Regex _rx = new Regex(
- @"^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}[AEIMQUYcgkosw048]=|[A-Za-z0-9+/][AQgw]==)?$",
- RegexOptions.Compiled);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement