Rebex
Products Downloads Buy Support Contact
Show / Hide Table of Contents

FileEncryption Class

Namespace: Rebex.Security
Assembly: Rebex.Security.dll (version 8.0.9673)

Provides high level API for encrypting and decrypting files and streams.

Syntax
public class FileEncryption
Inheritance
Object
FileEncryption
Inherited Members
Object.Equals(Object)
Object.Equals(Object, Object)
Object.GetHashCode()
Object.GetType()
Object.MemberwiseClone()
Object.ReferenceEquals(Object, Object)
Object.ToString()
Examples

See https://www.rebex.net/security.net/features/encryption-decryption.aspx for more code snippets.
See https://www.rebex.net/security.net/samples.aspx for ready-to-use samples.

Encrypting and decrypting files

// create an instance of encryption/decryption object
var encryption = new Rebex.Security.FileEncryption();

// change algorithm if needed (defaults are AES-XTS and SHA-1)
encryption.EncryptionAlgorithm = FileEncryptionAlgorithm.AesXts;
encryption.PasswordHashingAlgorithm = HashingAlgorithmId.SHA256;

// overwrite target file if it already exists
encryption.OverwriteExistingFile = true;

// specify password
encryption.SetPassword("password");

// encrypt a file
encryption.Encrypt(@"C:\MyData\Order.txt", @"C:\MyData\Order.txt.enc");

// decrypt a file
encryption.Decrypt(@"C:\MyData\Order.txt.enc", @"C:\MyData\Order.txt");

Constructors

Name Description
FileEncryption()

Creates a new instance of FileEncryption object.

Properties

Name Description
EncryptionAlgorithm

Gets or sets the encryption algorithm used for encryption and decryption.

EncryptionKeySize

Gets or sets the encryption key size (null indicates default key size).

OverwriteExistingFile

Get or sets a value indicating whether to overwrite existing target files.

PasswordHashingAlgorithm

Hashing algorithm for key derivation (derived from the password using PBKDF2 defined by RFC 2898). Supported algorithms: SHA1, SHA256, SHA384, SHA512.

PasswordIterations

Number of iterations for key derivation (derived from the password using PBKDF2 defined by RFC 2898).

XtsBlockSize

Gets or sets XTS algorithm block size in bytes. Must be multiple of 16. Default value is 65536, maximum number is 1048576. This is only used for AesXts. Use smaller buffer if you read very small parts of a stream from different places, or use larger buffer if you do sequential reads of large blocks. Setting this value might negatively impact the performance.

Methods

Name Description
Decrypt(Stream, Stream)

Decrypts data from a source stream into a target stream.

Decrypt(String, String)

Decrypts a source file into a target file.

DecryptAsync(Stream, Stream, Object)

Begins asynchronous Decrypt operation. Decrypts data from a source stream into a target stream.

DecryptAsync(String, String, Object)

Begins asynchronous Decrypt operation. Decrypts a source file into a target file.

Encrypt(Stream, Stream)

Encrypts data from a source stream into a target stream.

Encrypt(String, String)

Encrypts a source file into a target file.

EncryptAsync(Stream, Stream, Object)

Begins asynchronous Encrypt operation. Encrypts data from a source stream into a target stream.

EncryptAsync(String, String, Object)

Begins asynchronous Encrypt operation. Encrypts a source file into a target file.

SetPassword(Byte[])

Sets password for encryption and decryption.

SetPassword(Byte[], KeyDerivationAlgorithm)

Sets password for encryption and decryption.

SetPassword(String)

Sets password for encryption and decryption.

SetPassword(String, KeyDerivationAlgorithm)

Sets password for encryption and decryption.

In This Article
© REBEX ČR s.r.o. Back to top
Privacy policy
Manage cookies