Skip to content

media sdk file crypting manager

Andre Lafleur edited this page Oct 8, 2026 · 6 revisions

About FileCryptingManager

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.

Supported files

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.

Passwords

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.

Output files

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 .g64 extension, regardless of the original file's extension.
  • G64x output is renamed to .g64x after the decrypted file validates as a G64x archive.

Start and complete an operation

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.

Threading

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.

Progress

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.

Failure and cancellation

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.

FileCryptingManager members

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.

FileEncryptionResult

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.

See also

Platform SDK

Plugin SDK

Workspace SDK

Media SDK

Macro SDK

Web SDK

Synergis RIO

Media Gateway

Genetec Web Player

Clone this wiki locally