Menu

Blowfish or Rijndael encryption

2005-09-01
2012-09-26
  • Nobody/Anonymous

    Hi there!
    I am writing a DLL which should get some data, encrypt them and then send them via query string to remote www server with php installed.

    PHP has a library called mcrypt which supports a lot of encryption algorithms, but I think that BF and AES are the safest.

    I have some big problems with encryption. This should be done in CBC mode. I do not have enough skills and knowledge to complete this task. That's why I am looking for a library which can do this. Raw implementation is too difficult for me.

    But on the other hand, all libraries are very big (about 1Mb i.e. Libmcrypt or Crypto++).

    Do you know any other libraries with only one or two algorithms implemented with CBC mode so the size wouldn't be so huge?

    Or maybe you know any tutorials how to do this?

    The most important thing is the size... which should be lower than 100k

    Thanks

     
    • Nobody/Anonymous

      s

       
    • Nobody/Anonymous

      Download some code from here:

      http://www.schneier.com/blowfish-download.html

      Cheers,

      Ian (cookies gone again...)

       
    • Nobody/Anonymous

      I have already visited this page, but I still do not know how to encrypt a string in CBC mode.

      The only source code that could be useful for me from http://www.schneier.com/blowfish-download.html is the reference code from SSleay 0.6.6 but I can't find blowfish.dll from this library.

      Any other ideas or suggestions?
      Please help...:)

       
    • Ian Walker

      Ian Walker - 2005-09-01

      Go to ftp://ftp.psy.uq.oz.au/pub/Crypto/SSL/

      Download the SSLeay-0.9.0b.tar.gz archive.

      Unpack the archive locally (I used 7-zip, which made a pigs ear of the symbolic links, but that won't matter)

      In the unpacked archive, navigate to the crypto\bf directory. From, here, copy the files:

      blowfish.h
      bf_locl.h
      bf_pi.h
      bf_enc.c
      bf_skey.c

      to your project directory, and then add them all to the project in Dev-C++ (actually, you only really need to add the .C files, but hey...)

      If you are programming in C++, you'll need to go to the project options, and make sure that the bf_enc.c and bf_skey.c are NOT set to compile as C++ (on the "Files" tab, select each file and untick the box)

      Hey presto, you can now use the BF_cbc_encrypt function. You won't get a DLL doing it this way - the functions will be statically linked into your EXE.

      Below is a sample program which I wrote which when added to a project as above compiles fine on my XP box with Dev-C++ 4.9.9.2:

      Hope this helps,

      Ian (cookies back again...)

      --- snip ---

      include <cstdlib>

      include <iostream>

      include "blowfish.h"

      const long KEY_LENGTH = 16;
      const long KEY_SEED = 0x1234;

      const long bf_len = 32;

      int main()
      {
      unsigned char bf_in[bf_len+1] = "1 2 3 4 5 6 7 8 9 10 11 12 13 14";
      unsigned char bf_enc[bf_len];
      unsigned char bf_dec[bf_len];
      unsigned char ucharkey[KEY_LENGTH];
      BF_KEY key_in;
      unsigned char ivec_start[8];
      unsigned char ivec_in[8];

      // Display the unencrypted string
      for (int i = 0; i &lt; bf_len; ++i) std::cout &lt;&lt; bf_in[i];
      std::cout &lt;&lt; std::endl;
      
      // Create a random key.  I wouldn't recommend the following in a
      // live environment......
      std::srand(KEY_SEED);
      for (int i = 0; i &lt; KEY_LENGTH; ++i) ucharkey[i] = std::rand();
      
      // Create a random initial vector.  I wouldn't recommend this either
      for (int i = 0; i &lt; 8; ++i) ivec_start[i] = std::rand();
      std::memcpy(ivec_in, ivec_start, 8);
      
      // Convert our key string to a BF-style key
      BF_set_key(&amp;key_in, KEY_LENGTH, ucharkey);
      
      // Encrypt our test string
      BF_cbc_encrypt(bf_in, bf_enc, bf_len, &amp;key_in, ivec_in, BF_ENCRYPT);
      
      // Display the encryted string
      for(int i = 0; i &lt; bf_len; ++i) std::cout &lt;&lt; bf_enc[i];
      std::cout &lt;&lt; std::endl;
      
      // reset the initial vector
      std::memcpy(ivec_in, ivec_start, 8);
      
      // Decrypt the test string
      BF_cbc_encrypt(bf_enc, bf_dec, bf_len, &amp;key_in, ivec_in, BF_DECRYPT);
      
      // Display the decrypted string
      for(int i = 0; i &lt; bf_len; ++i) std::cout &lt;&lt; bf_dec[i];
      std::cout &lt;&lt; std::endl;
      
      system(&quot;PAUSE&quot;);
      return 0;
      

      }

       
    • Nobody/Anonymous

      Thank you very much!
      It works :)

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.