Rebex Security
XTS-AES and other handy security classes for .NET
Download 30-day free trial Buy from $99More .NET libraries
-
Rebex SFTP
.NET SFTP client
-
Rebex SSH Shell
.NET SSH Shell
-
Rebex Total Pack
All Rebex .NET libraries together
Back to feature list...
File encryption/decryption
On this page:
Easy-to-use API
FileEncryption
object is very simple - just set a password and it's ready to encrypt:
// create an instance of encryption/decryption object var encryption = new FileEncryption(); // specify password encryption.SetPassword("secret password"); // encrypt a file encryption.Encrypt("dragon.jpg", "dragon.jpg.enc");
' create an instance of encryption/decryption object Dim encryption = New FileEncryption() ' specify password encryption.SetPassword("secret password") ' encrypt a file encryption.Encrypt("dragon.jpg", "dragon.jpg.enc")
AES encryption algorithm in XTS mode is used by default.
This is the same mode used by the more powerful XtsStream
object.
Several encryption algorithms
FileEncryption
supports several encryption algorithms:
Algorithm | Description |
---|---|
AesXts |
XTS-AES, a standard algorithm for protection of stored data defined by IEEE P1619. Compatible with XtsStream object. |
AesCbc | AES in CBC mode. |
TripleDesCbc | 3DES in CBC mode. |
TwofishCbc | Twofish in CBC mode. |
To specify which one to use, set EncryptionAlgorithm
property:
// create an instance of encryption/decryption object var encryption = new FileEncryption(); // specify algorithm encryption.EncryptionAlgorithm = FileEncryptionAlgorithm.TripleDesCbc; // specify password encryption.SetPassword("secret password"); // encrypt a file encryption.Encrypt("dragon.jpg", "dragon.jpg.enc");
' create an instance of encryption/decryption object Dim encryption = New FileEncryption() ' specify algorithm encryption.EncryptionAlgorithm = FileEncryptionAlgorithm.TripleDesCbc ' specify password encryption.SetPassword("secret password") ' encrypt a file encryption.Encrypt("dragon.jpg", "dragon.jpg.enc")
Encrypting/decrypting a file
Use Encrypt
method to encrypt files and Decrypt
method to decrypt them. A OverwriteExistingFile
option can be useful as well.
// create an instance of encryption/decryption object var encryption = new FileEncryption(); // overwrite target file if it already exists encryption.OverwriteExistingFile = true; // specify password encryption.SetPassword("secret password"); // encrypt a file encryption.Encrypt("dragon.jpg", "dragon.jpg.enc"); // decrypt a file encryption.Decrypt("dragon.jpg.enc", "dragon.jpg");
' create an instance of encryption/decryption object Dim encryption = New FileEncryption() ' overwrite target file if it already exists encryption.OverwriteExistingFile = True ' specify password encryption.SetPassword("secret password") ' encrypt a file encryption.Encrypt("dragon.jpg", "dragon.jpg.enc") ' decrypt a file encryption.Decrypt("dragon.jpg.enc", "dragon.jpg")
Encrypting/decrypting a stream
FileEncryption
works with streams as well and it's just as simple as with files.
// create an instance of encryption/decryption object var encryption = new FileEncryption(); // specify password encryption.SetPassword("secret password"); // encrypt a stream // (reads data from input and encrypts it) encryption.Encrypt(input, encryptedOutput); // decrypt a stream // (reads data from encryptedInput and decrypts it) encryption.Decrypt(encryptedInput, output);
' create an instance of encryption/decryption object Dim encryption = New FileEncryption() ' specify password encryption.SetPassword("secret password") ' encrypt a stream ' (reads data from input and encrypts it) encryption.Encrypt(input, encryptedOutput) ' decrypt a stream ' (reads data from encryptedInput and decrypts it) encryption.Decrypt(encryptedInput, output)
Back to feature list...