Thank you for answering. The file does not include any CR or LF but I have noticed that is saved in UTF-8. Does it has anything to do with the problem?
If I read the file with a program with the code below the result is the same as the command line but, if I take the content of a file and put it in const unsigned char data[] it does not. My program will generate a string that has to be signed (md5 and RSA key). Which method will assure that I have a valid signed string: Write that string to a file and read it back to sign it? Or pass the string as an argument to a function and sign it? ( this is I would like to do but digest is different) TIA Luis Hernandez Dave Thompson-5 wrote: > >> From: owner-openssl-us...@openssl.org On Behalf Of lu_hernan >> Sent: Friday, 04 February, 2011 19:14 > >> openssl dgst -md5 sometextdata.txt >> >> it gives an answer XYZ >> >> but using this code en visual c++: >> const unsigned char data[]="text from file: sometextdata.txt"; >> unsigned char md[MD5_DIGEST_LENGTH]; >> MD5(data, strlen(data), md); >> >> it gives ABC as result. >> > Make sure the data is exactly byte-for-byte the same. > In particular, does the file have a CR-LF, or maybe just LF, > at the end? My ancient MSVC++6 (circa 1998) has an option > on File / Open: OpenAs=Binary . If that or something similar > is available, it should show exactly what's in the file. > If not do a simple program like: > > #include <stdio.h> > int main(void){ > FILE * fp = fopen ("sometextdata.txt", "rb"); /* b matters on Win */ > unsigned char buff[99999]; int i, n = fread (buff,1,sizeof buff, fp); > for( i = 0; i < n; i++ ) printf ("%c%02X", " \n"[!(i&0xF)], buff[i]); > printf ("\n"); fclose (fp); return 0; } > > > ______________________________________________________________________ > OpenSSL Project http://www.openssl.org > User Support Mailing List openssl-users@openssl.org > Automated List Manager majord...@openssl.org > > -- View this message in context: http://old.nabble.com/command-line-resul-ok-but-not-c%2B%2B-code-tp30849236p30852147.html Sent from the OpenSSL - User mailing list archive at Nabble.com. ______________________________________________________________________ OpenSSL Project http://www.openssl.org User Support Mailing List openssl-users@openssl.org Automated List Manager majord...@openssl.org