Hi all,

I'm having what seems to be a strange problem. I have code to encrypt some text using 
blowfish, and corresponding code to decrypt it. This works on compiler A: I can 
encrypt some text, and then decrypt the encrypted data correctly. This also works on 
compiler B: again I can have compiler B encrypt the text (using the same key) and have 
it decrypt the resulting data. The problem is that if I have compiler A encrypt the 
text, compiler B can't decrypt it (or vice versa)!

In other words, they are each producing different encrypted data based on the same 
text and same key. Is this expected? I would like my application (and it's data files) 
to be used across multiple platforms which is how I'm running into this. My current 
test is just using VC++6 (with the latest OpenSSL) and the latest version of Cygwin 
(with whatever version of OpenSSL it comes with).

The code I'm using to encrypt in my test is below. Is there something wrong with it (I 
stole most of it from some OpenSSL example I seem to recall). This routine produces 
different encrypted data on the two compliers. Any ideas?

Thanks!


  std::string  output;
  const char*  text   = "This is just a test to see if this works";
  std::string  keystr = "testkey";

  //
  // Generate a 'real' key and initialization vector based on keystr
  //
  
  unsigned char iv[EVP_MAX_IV_LENGTH];
  unsigned char key[EVP_MAX_KEY_LENGTH];

  EVP_BytesToKey( EVP_bf_cbc(), EVP_md5(), (unsigned char*)"quik",
                  (unsigned char*)keystr.c_str(), keystr.size(), 1, key, iv );

  //
  // Perform the encrpytion
  //

  EVP_CIPHER_CTX  context;
  
  EVP_CipherInit( &context, EVP_bf_cbc(), key, iv, 1 );

  const int KBlockSize = 50;
  char      out[KBlockSize+8];
  int       pos = 0;

  for( ;; )
  {
      unsigned char* in    = (unsigned char*) &text[pos];
      int            inLen = ((strlen(text)-pos) > KBlockSize) ? KBlockSize : 
(strlen(text)-pos);

      if( inLen < 1 )
          break;

      pos += inLen;

      int outLen = KBlockSize + 8;

      EVP_CipherUpdate( &context, (unsigned char*)out, &outLen, in, inLen );

      output.append( out, outLen );
  }

  int outLen = KBlockSize + 8;

  EVP_CipherFinal( &context, (unsigned char*)out, &outLen );

  output.append( out, outLen );

-Bill Klein <[EMAIL PROTECTED]>


______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    [EMAIL PROTECTED]
Automated List Manager                           [EMAIL PROTECTED]

Reply via email to