buff[1024] != out[512 + 8];

Lee Melville wrote:

> I am trying to encrypt a file and have tried allsorts to get the thing
> working.  What am i doing wrong?  It seems to corrupt within the while llop
> that updates the encryption.
>
> thanks in advance
>
> Lee Melville
>
> Here is 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;
>  //EVP_MD *md;
>  int i;
>  char buff[1024];
>
>  CFile fileIn;
>  fileIn.Open("A:\\test.txt", CFile::typeBinary | CFile::modeRead, NULL);
>  CFile fileOut;
>  fileOut.Open("A:\\test.enc", CFile::typeBinary | 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_EncryptInit(&ctx, ciph, (unsigned char *)key, (unsigned char *)iv);
>  cout << "begin update:" << endl;
>
>  i=0;
>  //fileIn.Read(&buff,0);
>  i++;
>  while (i = (fileIn.Read(buff, sizeof buff)) != NULL){
>   cout << "test: " << buff << " : " << outl << endl;
>   EVP_EncryptUpdate(&ctx, out, &outl, (unsigned char *)buff, 512);
>   fileOut.Write(&out, outl);
>   i++;
>  }
>
>  EVP_EncryptFinal(&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]

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

Reply via email to