Net Encryption Library
DecryptStream Method
Example 






KellermanSoftware.NetEncryptionLibrary Namespace > Encryption Class : DecryptStream Method
The encryption algorithm to use
The encryption password
The encrypted stream
The output decrypted stream
If true, the stream is base64 encoded
Decrypt a stream using the selected Decryption provider
Syntax
'Declaration
 
Public Function DecryptStream( _
   ByVal encryptionType As EncryptionProvider, _
   ByVal key As System.String, _
   ByVal inputStream As System.IO.Stream, _
   ByVal outputStream As System.IO.Stream, _
   ByVal useBase64 As System.Boolean _
) As System.Boolean
'Usage
 
Dim instance As Encryption
Dim encryptionType As EncryptionProvider
Dim key As System.String
Dim inputStream As System.IO.Stream
Dim outputStream As System.IO.Stream
Dim useBase64 As System.Boolean
Dim value As System.Boolean
 
value = instance.DecryptStream(encryptionType, key, inputStream, outputStream, useBase64)
public System.bool DecryptStream( 
   EncryptionProvider encryptionType,
   System.string key,
   System.IO.Stream inputStream,
   System.IO.Stream outputStream,
   System.bool useBase64
)
public function DecryptStream( 
    encryptionType: EncryptionProvider;
    key: System.String;
    inputStream: System.IO.Stream;
    outputStream: System.IO.Stream;
    useBase64: System.Boolean
): System.Boolean; 
public function DecryptStream( 
   encryptionType : EncryptionProvider,
   key : System.String,
   inputStream : System.IO.Stream,
   outputStream : System.IO.Stream,
   useBase64 : System.boolean
) : System.boolean;
public: System.bool DecryptStream( 
   EncryptionProvider encryptionType,
   System.string* key,
   System.IO.Stream* inputStream,
   System.IO.Stream* outputStream,
   System.bool useBase64
) 
public:
System.bool DecryptStream( 
   EncryptionProvider encryptionType,
   System.String^ key,
   System.IO.Stream^ inputStream,
   System.IO.Stream^ outputStream,
   System.bool useBase64
) 

Parameters

encryptionType
The encryption algorithm to use
key
The encryption password
inputStream
The encrypted stream
outputStream
The output decrypted stream
useBase64
If true, the stream is base64 encoded
Example
Encryption encryption = new Encryption(); //Trial Mode
//Encryption encryption = new Encryption("place user name here", "place license key here"); //License Mode
 
MemoryStream input = new MemoryStream();
 
for (int i = 0; i < 255; i++)
    input.WriteByte((byte)i);
 
input.Seek(0, SeekOrigin.Begin);
 
MemoryStream encryptedStream = new MemoryStream();
encryption.EncryptStream(EncryptionProvider.Rijndael, "My Password", input, encryptedStream, false);
encryptedStream.Seek(0, SeekOrigin.Begin);
 
MemoryStream decryptedStream = new MemoryStream();
encryption.DecryptStream(EncryptionProvider.Rijndael, "My Password", encryptedStream, decryptedStream, false);
decryptedStream.Seek(0, SeekOrigin.Begin);
 
input.Seek(0, SeekOrigin.Begin);
 
bool decryptedSucessfully = true;
for (int i = 0; i < input.Length; i++)
{
    byte inputByte = (byte)input.ReadByte();
    byte decryptedByte = (byte)decryptedStream.ReadByte();
 
    if (inputByte != decryptedByte)
    {
        decryptedSucessfully = false;
        break;
    }
}
 
Console.WriteLine("Decrypted successfully: {0}", decryptedSucessfully);
Dim encryption As New Encryption() 'Trial Mode
'Dim encryption As New Encryption("place user name here", "place license key here") 'License Mode
 
Dim input As New MemoryStream()
 
For i As Integer = 0 To 254
    input.WriteByte(CByte(i))
Next i
 
input.Seek(0, SeekOrigin.Begin)
 
Dim encryptedStream As New MemoryStream()
encryption.EncryptStream(EncryptionProvider.Rijndael, "My Password", input, encryptedStream, False)
encryptedStream.Seek(0, SeekOrigin.Begin)
 
Dim decryptedStream As New MemoryStream()
encryption.DecryptStream(EncryptionProvider.Rijndael, "My Password", encryptedStream, decryptedStream, False)
decryptedStream.Seek(0, SeekOrigin.Begin)
 
input.Seek(0, SeekOrigin.Begin)
 
Dim decryptedSucessfully As Boolean = True
For i As Integer = 0 To input.Length - 1
    Dim inputByte As Byte = CByte(input.ReadByte())
    Dim decryptedByte As Byte = CByte(decryptedStream.ReadByte())
 
    If inputByte <> decryptedByte Then
        decryptedSucessfully = False
        Exit For
    End If
Next i
 
Console.WriteLine("Decrypted successfully: {0}", decryptedSucessfully)
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

Encryption Class
Encryption Members