I am trying to create a message digest of a file and have created a small
program to spawn the openssl.exe and create a digest, and then use the
libraries to do it on the same file, the problem is i am getting differing
digest values back.  Somethings wrong but i cant see what.

plz help

Lee Melville


here is the code section;-


// ###############################################

 // Spawn the openssl.exe and create an md5 digest on a file

 int p;
 cout << "ready to run openssl.exe..." << endl;
 p = _spawnl( _P_WAIT,
"D:\\Source\\dgst1\\Debug\\openssl.exe","dgst","D:\\crap.txt", NULL);
 cout << endl << "p = " << p << endl;


// ################################################

 // now do the same but using the libraries

 EVP_MD_CTX mdctx;
 const EVP_MD *md;
 unsigned char md_value[EVP_MAX_MD_SIZE];
 unsigned int md_len;
 int i=0;
 char *buff;
 unsigned long len=0;

 OpenSSL_add_all_digests();

 CFile file;
 file.Open("D:\\crap.txt", CFile::typeBinary | CFile::modeRead, NULL);

 md = EVP_md5();
 EVP_DigestInit(&mdctx, md);

 len = file.GetLength();
 file.Read(&buff,0);
 i++;
 while(i<=len){
      EVP_DigestUpdate(&mdctx, &buff, 1);
      file.Read(&buff,1);
      i++;
 }
 cout << endl;
 EVP_DigestUpdate(&mdctx, &buff, 1);
 EVP_DigestFinal(&mdctx, md_value, &md_len);
 printf("Digest is: ");
 for(i = 0; i < md_len; i++) printf("%02x", md_value[i]);
 printf("\n");


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

Reply via email to