Security tutorial
Applies to: Rebex Total Pack, Rebex Security
Table of content
Namespaces and assemblies
To use the features of Rebex Security for .NET described here, you have to reference
the Rebex.Security.dll and Rebex.Common.dll assembly in your project.
It contains the FileEncryption
and other classes in Rebex.Security namespace.
In your source files, import the following namespace:
using Rebex.Security;
Imports Rebex.Security
Security basics
There are two typical uses of crypting
- encryption
- decryption
For encryption one must use any password as encryption key. For succesful decryption of encrypted file
one must know the password used for encryption of the file. There are several crypting algorythms,
the supported ones are enumerated in FileEncryptionAlgorithm
enum.
First of all there is a need of construction FileEncryption
class and setting password for encryption.
// create encryption class FileEncryption cryptor = new FileEncryption(); // set password for encryption cryptor.SetPassword("password"); // use information provided above for encrypting and decrypting // ...
' create encryption class Dim cryptor As FileEncryption = New FileEncryption() ' set password for encryption cryptor.SetPassword("password") ' use information provided above for encrypting and decrypting ' ...
After this you are prepared for encryption and decryption of files or streams.
Encryption files
As soon as you have instance of FileEncryption
class and have set password you can encrypt file like in following sample.
// create encryption class FileEncryption cryptor = new FileEncryption(); // set password for encryption cryptor.SetPassword("password"); // encrypt file from fileToEncryptPath to encryptedFilePath cryptor.Encrypt(fileToEncryptPath, encryptedFilePath);
' create encryption class Dim cryptor As FileEncryption = New FileEncryption() ' set password for encryption cryptor.SetPassword("password") ' encrypt file from fileToEncryptPath to encryptedFilePath cryptor.Encrypt(fileToEncryptPath, encryptedFilePath)
Encryption streams
As soon as you have instance of FileEncryption
class and have set password you can encrypt stream like in following sample.
// create encryption class FileEncryption cryptor = new FileEncryption(); // set password for encryption cryptor.SetPassword("password"); // encrypt stream from streamToEncrypt to encryptedStream stream cryptor.Encrypt(streamToEncrypt, encryptedStream);
' create encryption class Dim cryptor As FileEncryption = New FileEncryption() ' set password for encryption cryptor.SetPassword("password") ' encrypt stream from streamToEncrypt to encryptedStream stream cryptor.Encrypt(streamToEncrypt, encryptedStream)
Decryption files
As soon as you have instance of FileEncryption
class and have set password you can decrypt file like in following sample.
// create encryption class FileEncryption cryptor = new FileEncryption(); // set password for decryption cryptor.SetPassword("password"); // decrypt file from encryptedFilePath to decryptedFilePath cryptor.Decrypt(encryptedFilePath, decryptedFilePath);
' create encryption class Dim cryptor As FileEncryption = New FileEncryption() ' set password for decryption cryptor.SetPassword("password") ' decrypt file from encryptedFilePath to decryptedFilePath cryptor.Decrypt(encryptedFilePath, decryptedFilePath)
Decryption streams
As soon as you have instance of FileEncryption
class and have set password you can decrypt stream like in following sample.
// create encryption class FileEncryption cryptor = new FileEncryption(); // set password for encryption cryptor.SetPassword("password"); // decrypt stream from encryptedStream to decryptedStream stream cryptor.Encrypt(encryptedStream, decryptedStream);
' create encryption class Dim cryptor As FileEncryption = New FileEncryption() ' set password for decryption cryptor.SetPassword("password") ' decrypt stream from encryptedStream to decryptedStream stream cryptor.Encrypt(encryptedStream, decryptedStream)
Back to tutorial list...