CSharpTest.Net
Base64Stream Class
Members  Example  See Also  Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.Formatting Namespace : Base64Stream Class

Glossary Item Box

Provides reading and writing to a stream of base-64 characters.

Syntax

Visual Basic (Declaration) 
Public Class Base64Stream 
   Inherits System.Security.Cryptography.CryptoStream
C# 
public class Base64Stream : System.Security.Cryptography.CryptoStream 

Example

Library/Library.Test/TestSafe64Encoding.cs

C#Copy Code
byte[] data = new byte[256];
for (int i = 0; i < data.Length; i++)
    data[i] = (byte)i;

using (Stream mem = new MemoryStream())
{
    using (Stream io = new Base64Stream(new NonClosingStream(mem), CryptoStreamMode.Write))
        io.Write(data, 0, data.Length);


    Assert.AreEqual(((data.Length + 2) / 3 * 4), mem.Position);
    mem.Position = 0;
    string test = new StreamReader(mem).ReadToEnd();
    Assert.AreEqual(Convert.ToBase64String(data), test);
}
VB.NETCopy Code
Dim data As Byte() = New Byte(256) {}
Dim i As Integer = 0
While i < data.Length
    data(i) = DirectCast(i, Byte)
    System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
End While

Using mem As Stream = New MemoryStream()
    Using io As Stream = New Base64Stream(New NonClosingStream(mem), CryptoStreamMode.Write)
        io.Write(data, 0, data.Length)
    End Using


    Assert.AreEqual(((data.Length + 2) / 3 * 4), mem.Position)
    mem.Position = 0
    Dim test As String = New StreamReader(mem).ReadToEnd()
    Assert.AreEqual(Convert.ToBase64String(data), test)
End Using

Inheritance Hierarchy

System.Object
   System.MarshalByRefObject
      System.IO.Stream
         System.Security.Cryptography.CryptoStream
            CSharpTest.Net.Formatting.Base64Stream

Requirements

Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7

See Also

Generated with Document! X 2011 by Innovasys