Format of AES, Blowfish, Twofish, 3DES, etc. Symmetric Encrypted Data?


I know it isn’t listed in the documentation, but is there any method to test whether a file has been previously encrypted or not?  I would like to perform decryption on a file, but only if it is already encrypted.


A symmetric encryption algorithm is simply a transformation of bytes such that the output has the properties of randomly generated byte data.  There is no file format, and each byte value from 0x00 to 0xFF is virtually equally probable.

There is no single test that can be performed to determine if a file is already encrypted.  There are two solutions:

  1. Create your own test based on the  type of file being encrypted.  For example, if XML files are encrypted, then test to see if “<xml” is found in the beginning.
  2. Create your own simple “encrytped file format”.  For example, it could be as easy as writing a 4-byte “marker” at the beginning of every file containing encrypted data.  The marker would be a constant value, such as 0x01020304.  Your application could read the 1st 4 bytes of a file, and if equal to 0x01, 0x02, 0x03, 0x04, then it discards the marker and knows the remainder is the encrypted file data..

C# Blowfish Test Vectors

C# to match the Blowfish test vectors at this URL:

    // keys
    string[] key = new string[] { 
        "FEDCBA9876543210" };

    string[] plainText = new string[] { 

    string[] cipherBytes = new string[] { 
        "6B5C5A9C5D9E0A5A" };

    Chilkat.Crypt2 crypt = new Chilkat.Crypt2();

    bool success;
    success = crypt.UnlockComponent("Anything for 30-day trial");
    if (success != true)
        MessageBox.Show("Crypt component unlock failed");

    //  Attention: use "blowfish2" for the algorithm name:
    crypt.CryptAlgorithm = "blowfish2";

    //  CipherMode may be "ecb", "cbc", or "cfb"
    crypt.CipherMode = "ecb";

    //  KeyLength (in bits) may be a number between 32 and 448.
    //  128-bits is usually sufficient.  The KeyLength must be a
    //  multiple of 8.
    crypt.KeyLength = 64;

    //  The padding scheme determines the contents of the bytes
    //  that are added to pad the result to a multiple of the
    //  encryption algorithm's block size.  Blowfish has a block
    //  size of 8 bytes, so encrypted output is always
    //  a multiple of 8.
    crypt.PaddingScheme = 3;

    //  EncodingMode specifies the encoding of the output for
    //  encryption, and the input for decryption.
    //  It may be "hex", "url", "base64", or "quoted-printable".
    crypt.EncodingMode = "hex";

    int numTests = key.Length;
    int i;

    for (i = 0; i < numTests; i++)
        crypt.SetEncodedKey(key[i], "hex");

        string encStr = crypt.EncryptEncoded(plainText[i]);
        textBox1.Text += encStr + " should equal " + cipherBytes[i] + "\r\n";