Archived Forum Post

Index of archived forum posts

Question:

blowfish encryption using chilkat

Jun 06 '14 at 12:37

i'm trying to create a blowfish encryptdecrypt application just like in MIRC. for that i am using Chilkat libraries.

i'm not sure i have the exact settings as they are in mirc which using https://github.com/flakes/mirc_fish_10.

for example: i'm trying to encrypt the following text: "hi my name is" with the key: "Q1w2E3r4"

i'm using the following code to encode (also need to decode):

public Main()
{        
    var crypt = new Chilkat.Crypt2
    {
        CryptAlgorithm = "blowfish2",
        CipherMode = "ecb",
        KeyLength = 64,
        PaddingScheme = 0,
        EncodingMode = "base64",
    };

    bool success;
    success = crypt.UnlockComponent("Anything for 30-day trial");
    if (success != true)
    {
        return;
    }

    crypt.SetEncodedKey("Q1w2E3r4", "base64");

    encStr = crypt.EncryptStringENC("hi my name is");
    Console.WriteLine("Chilkat - Clear Text: hi my name");
    Console.WriteLine("Chilkat - Encoded: " + encStr);

}

please help to match the encoding


Answer

  1. Check to see if you really want "ECB" or "CBC" mode.
  2. Try to get both sides to match a published test vector. See below:

Test vectors for 64-bit blowfish are located here: https://www.schneier.com/code/vectors.txt

The 1st vector on the page is this:

key bytes               clear bytes             cipher bytes
0000000000000000        0000000000000000        4EF997456198DD78

Chilkat can reproduce these results with the following code:

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

crypt.CryptAlgorithm = "blowfish2";
            crypt.KeyLength = 64;
            crypt.CipherMode = "ecb";
            crypt.SetEncodedKey("0000000000000000", "hex");
            crypt.PaddingScheme = 3;    // In this case the input is already equal to the block size of the algorithm..
            crypt.EncodingMode = "hex";
            // Result is 4EF997456198DD78
            MessageBox.Show(crypt.EncryptEncoded("0000000000000000"));

Answer

for testing vector it works good - but still not same as mirc encryption. I wonder how come no similar project in chilkat for the one in mirc. I'm failing over and over to get the same results