Dart.PowerTCP.SslSockets Namespace : SymmetricCryptoStream Class |
A PipeStream type which performs bidirectional Cryptographic transforms to all data passing through the stream.
For a list of all members of this type, see SymmetricCryptoStream members.
System.Object
System.MarshalByRefObject
System.IO.Stream
Dart.PowerTCP.SslSockets.EnhancedStream
Dart.PowerTCP.SslSockets.SymmetricCryptoStream
[Visual Basic]
<LicenseProviderAttribute(SymmetricCryptoStreamLicenseProvider)>
Public Class SymmetricCryptoStream
Inherits EnhancedStream
[C#]
[LicenseProviderAttribute(SymmetricCryptoStreamLicenseProvider)]
public class SymmetricCryptoStream : EnhancedStream
[C++]
[LicenseProviderAttribute(SymmetricCryptoStreamLicenseProvider)]
public __gc class SymmetricCryptoStream : public EnhancedStream
[C++/CLI]
[LicenseProviderAttribute(SymmetricCryptoStreamLicenseProvider)]
public ref class SymmetricCryptoStream : public EnhancedStream
This class is useful for providing Private-key encryption, simplifying Microsoft's implementation. This class can be initialized with a TcpStream instance, for encrypting data to be sent over the network, with a FileStream instance, to encrypt a file, with a MemoryStream instance, to encrypt data in memory, or with any other type of Stream.
The following example demonstrates encrypting data and writing to a SymmetricCryptoStream on the fly.
[Visual Basic]
' 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\file.txt", System.IO.FileMode.Create)
Dim sc As New SymmetricCryptoStream(AlgorithmType.Rijndael, key, f)
' Always must flush the final block after writing.
sc.FlushFinalBlock()
f.Position=0
f.Close()
' The data is now encrypted and saved to a file. To decrypt, simply initialize a SymmetricCryptoStream
' in the same way as demonstrated above and read from the Filestream, instead of writing to it.
[C#]
// Create a key and some data.
byte[] key =
System.Text.Encoding.Default.GetBytes("test key");
byte[] data = System.Text.Encoding.Default.GetBytes("This is the plain text data");
// Create a FileStream to hold the data
System.IO.FileStream f = new System.IO.FileStream("C:\\encrypted\file.txt",
System.IO.FileMode.Create);
SymmetricCryptoStream sc = new SymmetricCryptoStream(key, f);
// Write to the file. This encrypts the data.
sc.Write(data, 0, data.Length);
// Always must flush the final block after writing.
sc.FlushFinalBlock();
f.Position=0;
f.Close();
// The data is now encrypted and saved to a file. To decrypt, simply initialize a SymmetricCryptoStream
// in the same way as demonstrated above and read from the Filestream, instead of writing to it.
Namespace: Dart.PowerTCP.SslSockets
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family
Assembly: Dart.PowerTCP.SslSockets (in Dart.PowerTCP.SslSockets.dll)
SymmetricCryptoStream Members | Dart.PowerTCP.SslSockets Namespace
Send comments on this topic.
Documentation version 1.1.2.0.
© 2008 Dart Communications. All rights reserved.