Preparing the Application

Preparing the SENx library for use in your application.

The application must initialize the SENx library and underlying encryption services by invoking the Initialize() function. Similarly, the application must use the Cleanup() function before terminating the application.

// initialize SENx library
SENx.Initialize();
Console.WriteLine("version: " + SENx.GetVersion());

// ...

// release all resources
SENx.Cleanup();

The following application example illustrates basic initialization of the library, generation of a public/private key-pair, and release of the library.

using EtherFax.Encryption;

static void Main(string[] args)
{
    // initialize SENx
    SENx.Initialize();
    Console.WriteLine("version: " + SENx.GetVersion());

    // create public/private key files, if needed
    if (!File.Exists("private_key.pem"))
    {
        var res = SENx.CreateKeyFiles(SENx.DefaultCurve, "private_key.pem", "public_key.pem");
        Console.WriteLine("CreateKeyFiles: " + res);
    }

    try
    {
        // let's do some crypto stuff
        // ...
    }
    catch (CryptoException e)
    {
        Console.WriteLine("CryptoException: {0} {1}", e.Result, e.Message);
    }

    // release all resources
    SENx.Cleanup();
}

When creating your public/private key-pair, the first parameter in CreateKeyfiles() is a string that specifies the name of the curve you'd like to use. In most cases, the SENx.DefaultCurve value may be used and is equivalent to "secp384r1". If the curve name is null, the default curve will be used.

Other popular curves are:

  • "secp256r1" also known as P-256
  • "secp521r1" also known as P-521

📘

Public and Private Keys

SENx stores and manages keys using the industry standard PEM format. Once you have locally generated a public/private key-pair for each instance of your application using the SENx.CreateKeyFiles() method, use the etherFAX Client SetPublicKey() function to upload only the generated public key to the etherFAX service. This action associates the public key with your account. When phone numbers (routes) associated with your account are queried, the public key will be provided to the remote peer. The peer may then choose to send encrypted documents as cryptograms to your account. Note, it is the developer's responsibility to ensure that the locally created private key file is protected and kept private.