Net Encryption Library
Format Preserving Encryption
Basic Tasks > Format Preserving Encryption

Format Preserving Encryption Overview

The FPEKELL1 Format Preserving Encryption Cipher has the following features:

 

How the encryption is performed

  1. The key is validated.  It must be in the range from ASCII 32 to 126 with a length of 262 characters.  Use the GenerateKey method to generate a random key.
  2. The block size is 256 bytes.
  3. There are 94 swap patterns defined, each character in the key will point to a swap pattern. 
  4. Perform three swaps of the substitution grid based on the first three characters of the key.
  5. Perform a fourth swap based on the last character of the plain text if there is more than one character to be encrypted.
  6. Perform a shift of the substitution grid based on the fourth character of the key.
  7. Replace the first character of the plain text.
  8. For characters 2 to 256, use the swap pattern of the key from 5 to 258 of the substitution grid.  The previously encrypted character determines the shift of the substitution grid.
  9. After all substitutions are processed. Perform three swaps of the encrypted text based on the key from 259 to 262.
  10. Perform a fourth swap of the encrypted text based on the length of the text.

 

C# Example

Encryption encryption = new Encryption(); //Trial Mode

//Encryption encryption = new Encryption("place user name here", "place license key here"); //License Mode

 

//Create a key. Save the key somewhere

string key = encryption.GenerateKey(EncryptionProvider.FPEKELL1);

Console.WriteLine("key:");

Console.WriteLine(key);

Console.WriteLine();

 

const string plain = "The quick brown fox jumps over the lazy dog.";

Console.WriteLine("plain: " + plain);

Console.WriteLine("plain.Length: " + plain.Length);

Console.WriteLine();

 

//Encrypt. The encrypted string will have the same length and it will always be in the printable character range

string encrypted = encryption.EncryptString(EncryptionProvider.FPEKELL1, key, plain);

Console.WriteLine("encrypted: " + encrypted);

Console.WriteLine("encrypted.Length: " + encrypted.Length);

Console.WriteLine();

 

string decrypted = encryption.DecryptString(EncryptionProvider.FPEKELL1, key, encrypted);

Console.WriteLine("decrypted: " + decrypted);

Console.WriteLine("decrypted.Length: " + decrypted.Length);

 

VB.NET Example

 

Dim encryption As New Encryption() 'Trial Mode

'Encryption encryption = new Encryption("place user name here", "place license key here"); //License Mode

 

'Create a key. Save the key somewhere

Dim key As String = encryption.GenerateKey(EncryptionProvider.FPEKELL1)

Console.WriteLine("key:")

Console.WriteLine(key)

Console.WriteLine()

 

Const plain As String = "The quick brown fox jumps over the lazy dog."

Console.WriteLine("plain: " & plain)

Console.WriteLine("plain.Length: " & plain.Length)

Console.WriteLine()

 

'Encrypt. The encrypted string will have the same length and it will always be in the printable character range

Dim encrypted As String = encryption.EncryptString(EncryptionProvider.FPEKELL1, key, plain)

Console.WriteLine("encrypted: " & encrypted)

Console.WriteLine("encrypted.Length: " & encrypted.Length)

Console.WriteLine()

 

Dim decrypted As String = encryption.DecryptString(EncryptionProvider.FPEKELL1, key, encrypted)

Console.WriteLine("decrypted: " & decrypted)

Console.WriteLine("decrypted.Length: " & decrypted.Length)