Advertisement
Guest User

Untitled

a guest
Dec 2nd, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. byte[] bytes = Convert.FromBase64String(cipherText);
  2.  
  3. public static class Base64Helper
  4. {
  5. public static byte[] TryParse(string s)
  6. {
  7. if (s == null) throw new ArgumentNullException("s");
  8.  
  9. if ((s.Length % 4 == 0) && _rx.IsMatch(s))
  10. {
  11. try
  12. {
  13. return Convert.FromBase64String(s);
  14. }
  15. catch (FormatException)
  16. {
  17. // ignore
  18. }
  19. }
  20. return null;
  21. }
  22.  
  23. private static readonly Regex _rx = new Regex(
  24. @"^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}[AEIMQUYcgkosw048]=|[A-Za-z0-9+/][AQgw]==)?$",
  25. RegexOptions.Compiled);
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement