Version: 1.1.1.0
Easily add SSL security and authentication to your Internet application in .NET. Includes components for TCP, Server, UDP, DNS, Ping, and Trace (trace route).

SymmetricCryptoStream Class

PowerTCP Mail for ActiveXThe SymmetricCryptoStream class is used within the .NET Framework to encrypt and decrypt data and is included as part of PowerTCP SSL Sockets for .NET. It provides private-key encryption functionality for any .NET application. Other features include:

  • Simplifies the .NET encryption implementation. Encrypt and decrypt data with only a few lines of code.
  • Initialize the SymmetricCryptoStream using a System.IO.MemoryStream for memory-based encryption/decryption (encrypting data in memory).
  • Initialize the SymmetricCryptoStream using a System.IO.FileStream for file-based encryption (encrypting data and writing it to a file, reading the data back and decrypting it).
  • Includes an ASP.NET sample which demonstrates encrypting and decrypting in memory
  • Includes a royalty-free license!

Code Example

How easy is the SymmetricCryptoStream to use? The following example demonstrates simple encryption.

VB.NET Example
' Create a key and some data.
Dim key As Byte() = System.Text.Encoding.Default.GetBytes("test key")
Dim data As Byte() = System.Text.Encoding.Default.GetBytes("This is the plain text data")

' Create a FileStream to hold the data
Dim f As System.IO.FileStream = New System.IO.FileStream("C:\encrypted", System.IO.FileMode.Create)
Dim sc As New Dart.PowerTCP.Sockets.SymmetricCryptoStream(key, f)

' Write to the file. This encrypts the data.
sc.Write(data, 0, data.Length)
sc.Position = 0
f.Close()

' Now read the data from the encrypted file to decrypt
f = new System.IO.FileStream("C:\encrypted", System.IO.FileMode.Open)
sc = new Dart.PowerTCP.Sockets.SymmetricCryptoStream(key, f)

data = new byte(sc.Length)
sc.Read(data, 0, data.Length)

sc.Position = 0
f.Close()

' Display results
Debug.WriteLine(System.Text.Encoding.Default.GetString(data))