Repository navigation
media sdk file crypting manager
FileCryptingManager encrypts and decrypts Security Center archive files on local disk. It uses the Begin / End async pattern with IAsyncResult for both operations, and reports byte progress through ProgressUpdated.
FileCryptingManager does not connect to Security Center and does not require an Engine.
Use FileCryptingManager only when your application targets .NET Framework. In that target, encryption creates an encrypted .gek file, and decryption reports success only when the decrypted content is a valid .g64 or .g64x archive.
Do not use FileCryptingManager for ASF, MP4, general-purpose file encryption, or .NET 8 applications.
Password support depends on the target framework.
When your application targets .NET 8, BeginEncryption and BeginDecryption complete with FileEncryptionResult.Success == false. No password length makes the operation succeed. Treat FileCryptingManager as unavailable for .NET 8 applications.
When your application targets .NET Framework, use an ASCII password that is exactly 16, 24, or 32 characters. Other lengths fail. Decryption requires the same password used for encryption. A wrong password returns Success == false, and FileEncryptionResult does not identify wrong passwords separately from other failures.
FileCryptingManager does not let you pass an output path. It creates a separate output file in the same folder as the input file.
| Operation | Generated output path |
|---|---|
BeginEncryption |
<input file name without extension>.gek |
BeginDecryption |
<input file name without extension>.g64, then the final file can be renamed after validation |
Existing files are not overwritten. If the generated path already exists, the file name gets a numeric suffix such as _1, _2, and so on.
The input file is not modified. For decryption, the final extension depends on the decrypted archive:
- G64 output uses the
.g64extension, regardless of the original file's extension. - G64x output is renamed to
.g64xafter the decrypted file validates as a G64x archive.
Construct the manager, subscribe to ProgressUpdated if the UI needs progress, and then call BeginEncryption or BeginDecryption with the input file, password, async callback, and async state. The returned IAsyncResult represents the operation. Call the matching End method on the same IAsyncResult to retrieve the FileEncryptionResult.
using System;
using System.ComponentModel;
using Genetec.Sdk.Media.Export;
private readonly FileCryptingManager m_cryptingManager = new FileCryptingManager();
private IAsyncResult m_encryptionOperation;
private void Encrypt(string inputFileName)
{
m_cryptingManager.ProgressUpdated += OnCryptingProgressUpdated;
m_encryptionOperation = m_cryptingManager.BeginEncryption(
inputFileName,
"0123456789abcdef",
OnEncryptionCompleted,
state: null);
}
private void OnEncryptionCompleted(IAsyncResult asyncResult)
{
m_cryptingManager.ProgressUpdated -= OnCryptingProgressUpdated;
FileEncryptionResult result = m_cryptingManager.EndEncryption(asyncResult);
if (result.Success)
{
RegisterEncryptedFile(result.OutputFile);
}
}
private void OnCryptingProgressUpdated(object sender, ProgressChangedEventArgs e)
{
UpdateProgress(e.ProgressPercentage);
}Decryption follows the same pattern with BeginDecryption and EndDecryption.
The completion callback and ProgressUpdated handler can run on a worker thread. In Workspace or WPF code, marshal back to the UI dispatcher before updating controls.
private void OnCryptingProgressUpdated(object sender, ProgressChangedEventArgs e)
{
if (!m_dispatcher.CheckAccess())
{
m_dispatcher.BeginInvoke(
new Action<object, ProgressChangedEventArgs>(OnCryptingProgressUpdated),
sender,
e);
return;
}
m_statusDialog.Progress = e.ProgressPercentage;
}The state argument passed to BeginEncryption or BeginDecryption belongs to the returned IAsyncResult. It is not the progress event state.
ProgressUpdated raises ProgressChangedEventArgs.
| Property | Meaning |
|---|---|
ProgressPercentage |
Integer percentage from 0 to 100 based on bytes processed from the input stream. |
UserState |
Not set by FileCryptingManager for file encryption and decryption progress. |
A progress value of 100 means the file bytes were processed. It does not guarantee success. Decryption still validates the resulting archive after the final progress update, so an operation can reach 100 and then return Success == false.
Always inspect FileEncryptionResult.Success before using OutputFile.
| Result | Meaning |
|---|---|
Success == true |
The operation succeeded and OutputFile contains the output path. |
Success == false |
The operation did not produce a usable output file. Do not register or open OutputFile. |
Failure can be caused by an unreadable input file, an output file that cannot be created, an invalid password length, a wrong password, a corrupt or unsupported encrypted file, a read or write error, or cancellation. FileEncryptionResult exposes only Success and OutputFile; the detailed failure cause is not surfaced.
To cancel an operation, call CancelEncryption or CancelDecryption with the IAsyncResult returned by the matching Begin method. Cancellation is cooperative, so still call the matching End method to observe the final FileEncryptionResult.
Cancellation can leave a generated output file if the file was already created before the cancellation was processed. If your workflow lets users cancel encryption or decryption, include cleanup for incomplete generated files.
Dispose() does not cancel an operation. Cancel first when the workflow needs to stop active work, and then call the matching End method and dispose the manager when the workflow is finished.
| Member | Description |
|---|---|
BeginEncryption(string inputFileName, string password, AsyncCallback callback, object state) |
Start encryption and return the operation IAsyncResult. The output file is generated beside the input file with the .gek extension. |
EndEncryption(IAsyncResult) |
Wait for the encryption operation to finish and return FileEncryptionResult. |
BeginDecryption(string inputFileName, string password, AsyncCallback callback, object state) |
Start decryption and return the operation IAsyncResult. The output file is generated beside the input file. |
EndDecryption(IAsyncResult) |
Wait for the decryption operation to finish and return FileEncryptionResult. |
CancelEncryption(IAsyncResult) |
Request cancellation for an in-flight encryption operation. |
CancelDecryption(IAsyncResult) |
Request cancellation for an in-flight decryption operation. |
ProgressUpdated |
Event raised with ProgressChangedEventArgs while encryption or decryption is processing bytes. |
Dispose() |
Dispose the manager after the workflow is complete. |
| Property | Description |
|---|---|
Success |
true only when the operation completed successfully. |
OutputFile |
Final output file path when Success is true. |
When Success is false, the operation did not produce a usable output file and the application should not use OutputFile.
- About G64 converters: Converting G64 and G64x packages to ASF or MP4.
- About MediaFile: Inspecting an existing G64, G64x, or MP4 file on disk.
- About MediaExporter: Producing G64 and G64x export packages from Security Center recordings.
- Overview
- Connecting to Security Center
- SDK certificates
- Referencing SDK assemblies
- ASP.NET hosting
- SDK compatibility
- Migrating to modern .NET
- Entities
- Entity cache
- Entity loading, cache, and query options
- Detecting entity changes
- Entity change event reference
- Transactions
- Security Center events
- Actions
- Security Desk
- Custom events
- Event-to-actions
- Managing macros
- ReportManager
- ReportManager query reference
- Access control raw events
- DownloadAllRelatedData and StrictResults
- Privileges
- Partitions
- Entity write restrictions
- About custom fields
- About video
- About cameras
- Enrolling a video unit
- Ingesting third-party video
- Archiver and auxiliary archiver roles
- Archive transfer
- About access control
- About cardholders and credentials
- About doors, areas, elevators, and access points
- About access rules and schedules
- About access control units and interface modules
- Enrolling an access control unit
- Door templates
- Visitors
- Mobile credentials
- About threat levels
- About alarms
- About incidents
- Maps
- Logging
- Overview
- Localization
- Certificates
- Lifecycle
- Threading
- State management
- Configuration
- Restricted configuration
- Events
- Queries
- Request manager
- Database
- Entity ownership
- Engine extensions
- Entity mappings
- Server management
- Custom privileges
- Custom entity types
- Resolving non-SDK assemblies
- Deploying plugins
- Modern .NET support
- Overview
- Localization
- Certificates
- Creating modules
- Tasks
- Pages
- Components
- Tile extensions
- Services
- Contextual actions
- Custom actions
- Options extensions
- Configuration pages
- Monitors
- Shared components
- Commands
- Extending events
- Map extensions
- Timeline providers
- Image extractors
- Credential encoders
- Credential readers
- Cardholder fields extractors
- Badge printers
- Content builders
- Dashboard widgets
- Incidents
- Logon providers
- Pinnable content builders
- Custom report pages
- Overview
- Getting started
- Media file formats
- MediaPlayer
- VideoSourceFilter
- MediaExporter
- MediaFile
- G64 converters
- FileCryptingManager
- PlaybackSequenceQuerier
- PlaybackStreamReader
- OverlayFactory
- PtzCoordinatesManager
- AudioTransmitter
- AudioRecorder
- AnalogMonitorController
- Camera blocking
- Overview
- Getting started
- Referencing entities
- Entity operations
- About access control in the Web SDK
- About video in the Web SDK
- Users and user groups
- Partitions
- Custom fields
- Custom card formats
- Actions
- Events and alarms
- Incidents
- Reports
- Tasks
- Macros
- Custom entity types
- System endpoints
- Performance guide
- Reference
- Endpoints
- Constants
- Enumerations
- Under the hood
- Troubleshooting