Decrypting a Document

Decrypting a document using a SENxContext.

Decrypting a fax document (cryptogram) is much easier than the encryption process that created it. After receiving a fax document, the application can easily determine if the FaxImage content is a cryptogram by using the IsCryptogram() method. If the received fax contents are indeed a cryptogram, the process is essentially reversed.

In the following example, a SENxContext is created using the static method FromCryptogram(). Because the cryptogram contains all information necessary to create the context, it is done with only the cryptogram as the input. Once the context is created, the application loads the private key it has stored followed by the call to Decrypt(), which both validates and decrypts the information contained in the cryptogram. The resulting byte[] array is the original content as transmitted by the sender.

Details of this process are explained here


Programming Example

For the sake of brevity, this programming example has omitted error checking.

// initialize SENx

    // receive a fax
    var fax = client.GetFax(JobId);
    if (SENxContext.IsCryptogram(fax.FaxImage))
        // create context from cryptogram
        using (var decrypt = SENxContext.FromCryptogram(fax.FaxImage))
            // load private key
            res = decrypt.LoadKeyFromFile(PrivateKeyFile);
            Console.WriteLine("LoadKeyFromFile: " + res);

            // decrypt cryptogram
            var data = decrypt.Decrypt(cryptogram);
            if (data != null)
                // original now in data
                // ...
catch (CryptoException e)
    Console.WriteLine("CryptoException: {0} {1}", e.Result, e.Message);

// release all resources