Hi,

Ok i am nearly there, the following code encrypts a file (i think it does
anyhow), the test file that i use starts off as 22 bytes, the encrypted
version is 24 ( i am not sure this is relevent).  Anyhow the problem is when
i come to decrypt the file using the openssl command line tool it complains
about a bad magic number.  What is this?  My code is the problem
(obviously), but i dont know where this magic number fits in and hence i
havn't got a clue as to what to do.  Plz Help.

Thanks.
Lee Melville

heres the code;-

//--------------------------------------------------------------------------
-----

 OpenSSL_add_all_algorithms();

 char key[EVP_MAX_KEY_LENGTH];
 char iv[EVP_MAX_IV_LENGTH];
 EVP_CIPHER_CTX ctx;
 unsigned char out[512+8];
 int outl;
 char passwd[] = "password";
 EVP_CIPHER *ciph;
 int i,len;
 unsigned char buff[1024];
 unsigned char c;

 CFile fileIn;
 fileIn.Open("A:\\test.txt", CFile::typeBinary | CFile::modeRead, NULL);
 CFile fileOut;
 fileOut.Open("A:\\test.enc", CFile::typeBinary | CFile::modeCreate |
CFile::modeWrite, NULL);

 ciph = EVP_bf_cbc();
 EVP_BytesToKey(ciph,EVP_md5(),NULL,(unsigned char
*)passwd,strlen(passwd),1,(unsigned char *)key,(unsigned char *)iv);
 cout << "begin init:" << endl;
 EVP_CipherInit(&ctx, ciph, (unsigned char *)key, (unsigned char *)iv,1);
 cout << "begin update:" << endl;

 i=1;
 while (i != 0){
      len=0;
      while(i!=0){
            i=fileIn.Read(&c,1);
            buff[len]=c;
            len++;
            if(len>(512+8)) break;
      }
      EVP_CipherUpdate(&ctx, out, &outl, (unsigned char *)buff, len);
      fileOut.Write(&out, outl);
 }
 EVP_CipherFinal(&ctx, out, &outl);
 fileOut.Write(&out, outl);

 fileIn.Close();
 fileOut.Close();



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

Reply via email to