Net Encryption Library
DecryptMemoryStream Method
Example 






KellermanSoftware.NetEncryptionLibrary Namespace > Encryption Class : DecryptMemoryStream Method
The encryption algorithm to use
The encryption password
The stream to decrypt
Decrypt the memory stream using the selected Decryption provider
Syntax
'Declaration
 
Public Function DecryptMemoryStream( _
   ByVal encryptionType As EncryptionProvider, _
   ByVal key As System.String, _
   ByVal stream As System.IO.MemoryStream _
) As System.IO.MemoryStream
'Usage
 
Dim instance As Encryption
Dim encryptionType As EncryptionProvider
Dim key As System.String
Dim stream As System.IO.MemoryStream
Dim value As System.IO.MemoryStream
 
value = instance.DecryptMemoryStream(encryptionType, key, stream)
public System.IO.MemoryStream DecryptMemoryStream( 
   EncryptionProvider encryptionType,
   System.string key,
   System.IO.MemoryStream stream
)
public function DecryptMemoryStream( 
    encryptionType: EncryptionProvider;
    key: System.String;
    stream: System.IO.MemoryStream
): System.IO.MemoryStream; 
public function DecryptMemoryStream( 
   encryptionType : EncryptionProvider,
   key : System.String,
   stream : System.IO.MemoryStream
) : System.IO.MemoryStream;
public: System.IO.MemoryStream* DecryptMemoryStream( 
   EncryptionProvider encryptionType,
   System.string* key,
   System.IO.MemoryStream* stream
) 
public:
System.IO.MemoryStream^ DecryptMemoryStream( 
   EncryptionProvider encryptionType,
   System.String^ key,
   System.IO.MemoryStream^ stream
) 

Parameters

encryptionType
The encryption algorithm to use
key
The encryption password
stream
The stream to decrypt
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 = encryption.EncryptMemoryStream(EncryptionProvider.Rijndael, "My Password", input);
encryptedStream.Seek(0, SeekOrigin.Begin);
 
MemoryStream decryptedStream = encryption.DecryptMemoryStream(EncryptionProvider.Rijndael, "My Password", encryptedStream);
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 MemoryStream = encryption.EncryptMemoryStream(EncryptionProvider.Rijndael, "My Password", input)
encryptedStream.Seek(0, SeekOrigin.Begin)
 
Dim decryptedStream As MemoryStream = encryption.DecryptMemoryStream(EncryptionProvider.Rijndael, "My Password", encryptedStream)
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