public static string ByteArrayToBase64(byte[] ByteArray, bool Urlsafe = true) { string B64; B64 = System.Convert.ToBase64String(ByteArray); if (Urlsafe) { B64 = B64.TrimEnd('=').Replace('+', '-').Replace('/', '_'); } return(B64); }