private string Encode_WriteFragments(byte[] buf, int count, IRandomSource rng) { using (MemoryStream ms = new MemoryStream(buf.Length)) { using (Base64EncodingOutputStream base64Strm = new Base64EncodingOutputStream(ms, Encoding.UTF8)) { int idx = 0; int remain = count; while (remain > 0) { int len = Math.Min(rng.Next(256), remain); base64Strm.Write(buf, idx, len); idx += len; remain -= len; } } ms.Position = 0; using (StreamReader sr = new StreamReader(ms, Encoding.UTF8)) { string base64Str = sr.ReadToEnd(); return(base64Str); } } }
private string Encode(byte[] buf, int count) { using (MemoryStream ms = new MemoryStream(buf.Length)) { using (Base64EncodingOutputStream base64Strm = new Base64EncodingOutputStream(ms, Encoding.UTF8)) { base64Strm.Write(buf, 0, count); } ms.Position = 0; using (StreamReader sr = new StreamReader(ms, Encoding.UTF8)) { string base64Str = sr.ReadToEnd(); return(base64Str); } } }
private static string Encode(Span <byte> span) { using (MemoryStream ms = new MemoryStream(span.Length)) { using (Base64EncodingOutputStream base64Strm = new Base64EncodingOutputStream(ms, Encoding.UTF8)) { base64Strm.Write(span); } ms.Position = 0; using (StreamReader sr = new StreamReader(ms, Encoding.UTF8)) { string base64Str = sr.ReadToEnd(); return(base64Str); } } }