Class VideoDecryptorStream
- Namespace
- VisioForge.Core.VideoEncryption
- Assembly
- VisioForge.Core.dll
Provides a stream-based interface for decrypting encrypted video data with support for random access. This class creates and manages a VisioForge.Core.VideoEncryption.DecryptorStream instance that can be used to read decrypted data from an encrypted source stream on-the-fly, without requiring the entire file to be decrypted at once.
public class VideoDecryptorStream : IDisposableInheritance
Implements
Inherited Members
Remarks
This class is useful for scenarios where you need to decrypt video data in a streaming fashion, such as playing encrypted video files without fully decrypting them to disk first. The underlying VisioForge.Core.VideoEncryption.DecryptorStream supports seeking, allowing random access to any position in the decrypted data.
The class implements the IDisposable pattern to ensure proper cleanup of cryptographic resources. Always dispose of this object when finished, preferably using a using statement.
The decryption uses AES-128 in CBC mode with key derivation via PBKDF2. The password and salt must match those used during encryption with VisioForge.Core.VideoEncryption.VideoEncryptor.
Methods
DecryptToStream(Stream, string, byte[])
Creates and returns a decryption stream that reads from an encrypted source stream. The returned stream can be used to read decrypted data transparently as if it were unencrypted, and supports seeking to allow random access to any position in the decrypted data.
public Stream DecryptToStream(Stream encrypted, string key, byte[] salt = null)Parameters
encryptedStream-
The encrypted source stream to read from. Must be a valid stream with readable data.
keystring-
The decryption password. Must exactly match the password used during encryption and cannot be empty.
saltbyte[]-
Optional cryptographic salt for key derivation. If null, a salt is automatically derived from the key's MD5 hash. The salt must match the one used during encryption.
Returns
- Stream
-
A Stream that provides decrypted data when read from. This stream supports seeking for random access.
Remarks
The returned stream is managed internally by this VisioForge.Core.VideoEncryption.VideoDecryptorStream instance. When this object is disposed, the internal decryptor stream is also disposed.
The encrypted source stream will not be automatically disposed when this object is disposed,
as indicated by the leaveOpen: false parameter passed to the internal VisioForge.Core.VideoEncryption.DecryptorStream.
The caller remains responsible for disposing the encrypted stream.
Exceptions
- ArgumentException
-
Thrown when the key is empty.
- ArgumentException
-
Thrown when the salt is empty after automatic generation or when provided as an empty array.
- ArgumentException
-
Thrown when the encrypted stream is null or has a length of zero.
Dispose(bool)
Releases the unmanaged resources used by the VisioForge.Core.VideoEncryption.VideoDecryptorStream and optionally releases the managed resources.
protected virtual void Dispose(bool disposing)Parameters
disposingbool-
true to release both managed and unmanaged resources; false to release only unmanaged resources.
Remarks
This method is called by both the public VisioForge.Core.VideoEncryption.VideoDecryptorStream.Dispose method and the finalizer.
When called with disposing set to true, this method disposes
the internal decryptor stream and marks this instance as disposed.
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. Disposes the internal decryptor stream and suppresses finalization of this instance.
public void Dispose()Remarks
Call this method when you are finished using the VisioForge.Core.VideoEncryption.VideoDecryptorStream. It is recommended to use a using statement or using declaration to ensure this method is called automatically.
After calling this method, the object is in a disposed state and should not be used further.
~VideoDecryptorStream()
Finalizes an instance of the VisioForge.Core.VideoEncryption.VideoDecryptorStream class. Ensures that cryptographic resources are properly disposed even if VisioForge.Core.VideoEncryption.VideoDecryptorStream.Dispose was not explicitly called.
protected ~VideoDecryptorStream()Remarks
This finalizer is part of the dispose pattern and ensures that unmanaged resources are released even if the consumer forgets to call VisioForge.Core.VideoEncryption.VideoDecryptorStream.Dispose. However, it is always preferable to explicitly dispose of this object using a using statement or by calling VisioForge.Core.VideoEncryption.VideoDecryptorStream.Dispose directly.