Example #1
0
        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);
                }
            }
        }
Example #2
0
        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);
                }
            }
        }
Example #3
0
        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);
                }
            }
        }