Fort - For Developers

For developers Fort has an open source developer library available called FortMachine.dll. It's written in C#. FortMachine is available for free of charge under the GPL license. Source code is available on Github.

If you want to use FortMachine.dll in a closed source project where GPL license is not valid, it's possible to buy a license exception. Purchase it from here.

For translations, see How to translate?.

Examples

Here's some examples how easy it is to use FortMachine.dll to implement encryption in your own projects. Basically you do not need to know anything about cryptography in order to use file encryption part of the library. Using FortMachine.dll you can integrate support for Fort in your company's infrastructure for example.

Encrypting a file with FortMachine.dll

Please note that are these examples and they are not meant to be used directly.

using System;
using FortMachine;

namespace ConsoleApp
{
    class Program
    {
	static void Main(string[] args)
	{
	    string inputfile = "c:\\mysecretfile.txt";
	    string outputfile = "c:\\mysecretfile_encrypted.txt";
	    string password = "p2ssw0rd";
	    bool success;

	    FortFactory factory = new FortFactory();
	    IEncryptionMachine machine = factory.CreateEncryptionMachine();

	    success = machine.Encrypt2(password, inputfile, outputfile);

	    if (!success)
		Console.WriteLine(machine.GetLastErrorMessage());
	    else
		Console.WriteLine("File encrypted!");
	}
    }
}
		
Decrypting a file with FortMachine.dll
using System;
using FortMachine;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            string outputfile = "c:\\mysecretfile.txt";
            string inputfile = "c:\\mysecretfile_encrypted.txt.fortenc";
            string password = "p2ssw0rd";
            bool success;

            FortFactory factory = new FortFactory();
            IEncryptionMachine machine = factory.CreateEncryptionMachine();

            success = machine.Decrypt2(password, inputfile, outputfile);

            if (!success)
                Console.WriteLine(machine.GetLastErrorMessage());
            else
                Console.WriteLine("File decrypted!");
        }
    }
}					
		

Interface IEncryptionMachine

Instance of this can be created using class FortFactory. See the examples above.

namespace FortMachine
{
    public interface IEncryptionMachine
    {
	//Returns the file extension FortMachine uses for encrypted files
        string EncryptedFileExtension { get; }
	
	//Encrypt a file and save encrypted data to the outputpath. 
	//If KeepPlainFile is false, original file will be deleted.
	//Returns true on success. LastErrorMessage is set if an error occurs.
        bool Encrypt2(string passphrase, string inputpath, string outputpath, bool KeepPlainFile = false);
	
	//Decrypt file and save decrypted data to outputpath. Returns true on success.
	//Method sets LastErrorMessage on error.
        bool Decrypt2(string passphrase, string inputpath, string outputpath);
	
	//Returns last error message or an empty string if there are no errors.
        string GetLastErrorMessage();
	
	//Returns true if data is tampered. Can be called after decryption.
        bool IsDataTampered { get; }
	
	//Decrypt crypt byte array and return decrypted data as byte array.
	//Key must be 256 bits and IV 128 bits.
        byte[] Decrypt(byte[] cipher, byte[] key, byte[] IV);
	
	//Encrypt crypt byte array and return encrypted data as byte array.
	//Key must be 256 bits and IV 128 bits.
        byte[] Encrypt(byte[] plain, byte[] key, byte[] IV);
	
	//Returns instance of FortKey.
        FortKey CreateKey(string passphrase);
	
	//Returns new 128bit initialization vector.
        byte[] GetRandom16IV();
        
        //Returns cryptographically random data up to the length.
        byte[] GenerateRandomData(uint length);
    
        //Returns new instance of the FortKeyFile.
        //Parameter length should be 512 (for a 4096bit key)
        FortKeyFile GetNewKeyFile(uint length);
    
        //Preverse an existing keyfile to a file pointed by path.
        //Returns true on success, false on error. Sets the LastErrorMessage on failure.
        bool PreserveKeyfile(FortKeyFile keyFile, string path);
        
        //Loads FortKeyFile from location pointed by path.
        //Returns null on failure and sets the LastErrorMessage property.
        FortKeyFile LoadKeyfileFromDisk(string path);
    }
}
		

Class FortKey

namespace FortMachine
{
    //Default constructor
    public FortKey(string passphrase);

    //Returns 64 bit salt used with key generation.
    //Available after GetNew() is called.
    //Otherwise returns null.
    public byte[] Salt {get;}
 

    //Generate key using existing salt.
    //Salt must be 64 bits.
    public byte[] GetNew(byte[] salt);
      

    //Get new 256 bit key as byte array. This method also creates random salt
    //and stores it to salt property for later use.
    public byte[] GetNew();
      
    //Verify a passphrase against existing key. Static method.
    public static bool VerifyPassphrase(string passphrase, byte[] salt, byte[] key);
 }    
		

Class FortKeyFile

namespace FortMachine
{
    //Default constructor
    //Parameter data is the cryptographically random data that the key will contain
    //Length should be 512 for a 4096 bit key
    public FortKeyFile(byte[] data, uint length);

    //Returns an instance from a file.
    //On failure returns null.
    public static FortKeyFile LoadFromDisk(string path);
 
    //Returns Fort compatible passphrase presentation from the key data.
    //Can be used for IEncryption machine encrypt and decrypt methods.
    public string GetPassphrasePresentationFromData();
 }    
		

How to translate?

Translating Fort to different languages is very easy. First, install Fort extension and navigate to the installation path. By default, it's C:\Program Files\Fort - Crypto Extension for Windows\. Under that directory there's a sub directory called "Lang". In there you'll find all the available translations. You can copy the English.txt to a new language name and translate the strings.

The translation format is following: English string is here===This is where to type the translation after three = characters. Once you create new translation, for example Sweden.txt, you will see it in the list of available languages in the Fort settings dialog.

After you've tested your translation, you can submit it to us by email. We will then add it to the official installer package.