Net Encryption Library
EncryptBytes Method
Example 






KellermanSoftware.NetEncryptionLibrary Namespace > Encryption Class : EncryptBytes Method
The encryption algorithm to use
The encryption password
The bytes to encrypt
Encrypt bytes using the selected encryption provider
Syntax
'Declaration
 
Public Function EncryptBytes( _
   ByVal encryptionType As EncryptionProvider, _
   ByVal key As System.String, _
   ByVal input() As System.Byte _
) As System.Byte()
'Usage
 
Dim instance As Encryption
Dim encryptionType As EncryptionProvider
Dim key As System.String
Dim input() As System.Byte
Dim value() As System.Byte
 
value = instance.EncryptBytes(encryptionType, key, input)
public System.byte[] EncryptBytes( 
   EncryptionProvider encryptionType,
   System.string key,
   System.byte[] input
)
public function EncryptBytes( 
    encryptionType: EncryptionProvider;
    key: System.String;
    input: System.Bytearray of
): System.array of Byte; 
public function EncryptBytes( 
   encryptionType : EncryptionProvider,
   key : System.String,
   input : System.byte[]
) : System.byte[];
public: System.byte[]* EncryptBytes( 
   EncryptionProvider encryptionType,
   System.string* key,
   System.byte[]* input
) 
public:
System.array<byte>^ EncryptBytes( 
   EncryptionProvider encryptionType,
   System.String^ key,
   System.array<byte>^ input
) 

Parameters

encryptionType
The encryption algorithm to use
key
The encryption password
input
The bytes to encrypt
Example
Encryption encryption = new Encryption(); //Trial Mode
//Encryption encryption = new Encryption("place user name here", "place license key here"); //License Mode
 
byte[] input = new byte[255];
 
for (int i = 0; i < 255; i++)
    input[i] = (byte)i;
 
byte[] encryptedBytes = encryption.EncryptBytes(EncryptionProvider.Rijndael, "My password", input);
byte[] decryptedBytes = encryption.DecryptBytes(EncryptionProvider.Rijndael, "My password", encryptedBytes);
 
bool decryptedSucessfully = true;
for (int i = 0; i < input.Length; i++)
{
    if (input[i] != decryptedBytes[i])
    {
        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(254) As Byte
 
For i As Integer = 0 To 254
    input(i) = CByte(i)
Next i
 
Dim encryptedBytes() As Byte = encryption.EncryptBytes(EncryptionProvider.Rijndael, "My password", input)
Dim decryptedBytes() As Byte = encryption.DecryptBytes(EncryptionProvider.Rijndael, "My password", encryptedBytes)
 
Dim decryptedSucessfully As Boolean = True
For i As Integer = 0 To input.Length - 1
    If input(i) <> decryptedBytes(i) 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