Table of Contents

Class VideoDecryptor

Namespace
VisioForge.Core.VideoEncryption
Assembly
VisioForge.Core.dll

Provides cross-platform video decryption functionality using AES-128 encryption in CBC mode. This static class offers both synchronous and asynchronous methods for decrypting video files and streams that were previously encrypted using the corresponding VisioForge.Core.VideoEncryption.VideoEncryptor class.

public static class VideoDecryptor

Inheritance

Inherited Members

Remarks

This class implements AES-128 decryption in Cipher Block Chaining (CBC) mode. The decryption key and initialization vector (IV) are derived from the password and salt using PBKDF2 with 10,000 iterations.

For .NET 6.0 and later, PBKDF2 uses SHA-256 as the hash algorithm. For earlier versions, the default hash algorithm of Rfc2898DeriveBytes is used.

The password and salt used for decryption must exactly match those used during encryption. If no salt is provided, the same automatic salt generation logic from the password's MD5 hash is used, which must match the encryption process.

For stream-based decryption with random access support, consider using the VisioForge.Core.VideoEncryption.VideoDecryptorStream class instead.

Methods

Decrypt(string, string, string, byte[], EncryptionProgressCallback)

Synchronously decrypts an encrypted video file and saves the result to a new file. This method blocks the calling thread until the decryption operation is complete.

public static void Decrypt(string encryptedFileName, string decryptedFileName, string password, byte[] salt = null, EncryptionProgressCallback progress = null)

Parameters

encryptedFileName string

The path to the encrypted file to decrypt. Must be a valid, accessible file path.

decryptedFileName string

The path where the decrypted file will be saved. Any existing file at this path will be deleted before the operation begins.

password string

The password used for decryption. Must exactly match the password used during encryption.

salt byte[]

Optional cryptographic salt for key derivation. If null, a salt is derived from the password's MD5 hash. Must match the salt used during encryption.

progress EncryptionProgressCallback

Optional callback delegate to receive progress updates during decryption, reported as percentage values from 0 to 100.

Remarks

The source file is not modified; only the destination file is created or overwritten. Both file streams are properly disposed after the operation completes.

Decrypt(Stream, Stream, string, byte[], EncryptionProgressCallback)

Synchronously decrypts data from an encrypted stream and writes the result to an output stream. This method reads encrypted data in chunks, decrypts it using AES-128 encryption in CBC mode, and writes the decrypted data to the output stream. This method blocks the calling thread until the decryption operation is complete.

public static void Decrypt(Stream encryptedStream, Stream decryptedStream, string password, byte[] salt = null, EncryptionProgressCallback progress = null)

Parameters

encryptedStream Stream

The input stream containing encrypted data. The stream must support reading and have a defined length.

decryptedStream Stream

The output stream where decrypted data will be written. The stream must support writing and be flushed after completion.

password string

The password used for decryption. Must exactly match the password used during encryption.

salt byte[]

Optional cryptographic salt for key derivation. If null, a salt is derived from the password's MD5 hash. Must match the salt used during encryption.

progress EncryptionProgressCallback

Optional callback delegate to receive progress updates during decryption, reported as percentage values from 0 to 100.

Remarks

The decryption is performed using a VisioForge.Core.VideoEncryption.DecryptorStream wrapper that handles block-aligned decryption operations. Data is read in chunks for efficient processing.

The streams are not disposed by this method; the caller is responsible for stream lifetime management. The output stream is flushed after all data has been written.

DecryptAsync(string, string, string, byte[], EncryptionProgressCallback)

Asynchronously decrypts an encrypted video file and saves the result to a new file.

public static Task DecryptAsync(string sourceFile, string destFile, string password, byte[] salt = null, EncryptionProgressCallback progress = null)

Parameters

sourceFile string

The path to the encrypted source file to decrypt. Must be a valid, accessible file path.

destFile string

The path where the decrypted file will be saved. Any existing file at this path will be deleted before the operation begins.

password string

The password used for decryption. Must exactly match the password used during encryption.

salt byte[]

Optional cryptographic salt for key derivation. If null, a salt is derived from the password's MD5 hash. Must match the salt used during encryption.

progress EncryptionProgressCallback

Optional callback delegate to receive progress updates during decryption, reported as percentage values from 0 to 100.

Returns

Task

A Task representing the asynchronous decryption operation.

Remarks

This method runs the decryption operation on a background thread using Run(Action). The source file is not modified; only the destination file is created or overwritten.

DecryptAsync(Stream, Stream, string, byte[], EncryptionProgressCallback)

Asynchronously decrypts data from an encrypted stream and writes the result to an output stream.

public static Task DecryptAsync(Stream encryptedStream, Stream decryptedStream, string password, byte[] salt = null, EncryptionProgressCallback progress = null)

Parameters

encryptedStream Stream

The input stream containing encrypted data. The stream must support reading and have a defined length.

decryptedStream Stream

The output stream where decrypted data will be written. The stream must support writing.

password string

The password used for decryption. Must exactly match the password used during encryption.

salt byte[]

Optional cryptographic salt for key derivation. If null, a salt is derived from the password's MD5 hash. Must match the salt used during encryption.

progress EncryptionProgressCallback

Optional callback delegate to receive progress updates during decryption, reported as percentage values from 0 to 100.

Returns

Task

A Task representing the asynchronous decryption operation.

Remarks

This method runs the decryption operation on a background thread using Run(Action). The streams are not disposed by this method; the caller is responsible for stream lifetime management.

The input stream position is advanced as data is read, and the output stream receives the decrypted data.