You are again using strlen(): hexprint(op, strlen(op));
> -----Original Message----- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of kaustubh mendki > Sent: Tuesday, July 19, 2005 3:03 PM > To: Ken Goldman > Cc: openssl-users@openssl.org > Subject: Re: MD5 not returning hash for string ending with "." > > > Hi Ken, > > Yes, hash can contain printable as well as > nonprintable chars.As I mentioned this code > was working with other strings and giving > correct hash length(16).To eliminate this > issue, i converted these chars to hex. > Now code look like this: > > #include <stdio.h> > #include "openssl/md5.h" > > void hexprint(unsigned char *data, int len) > { > int i; > for(i = 0;i < len;i++) > { /* "%02x" for lowercase, "%02X" for > uppercase hexidecimal letters */ > printf("%02x", data[i]); > } > } > > int main() > { > unsigned char var[]="k."; > unsigned char *op; > > op = MD5(var,strlen(var),NULL); > hexprint(op, strlen(op)); > return 0; > } > > Atleast this should work ..but its not > working either for string "k.". For any > other string working perfectly. > > Wonder if its a bug! > > Thanks, > Kaustubh > > > --- Ken Goldman <[EMAIL PROTECTED]> wrote: > > > > Date: Tue, 19 Jul 2005 04:30:03 -0700 (PDT) > > > From: kaustubh mendki <[EMAIL PROTECTED]> > > > > > > I am trying a simple program to get MD5 hash of > > > any string.The program is as follows: > > > > > > #include <stdio.h> > > > #include "openssl/md5.h" > > > > > > int main() > > > { > > > unsigned char var[]="k."; > > > unsigned char *op; > > > > > > op = MD5(var,strlen(var),NULL); > > > printf("\nHash= %s\tLen= %d",op, > > strlen(op)); > > > return 0; > > > } > > > > > > I compiled it with: gcc -lcrypto -o try try.c > > > The above code is returning empty hash with 0 > > length. > > > But with strings like ".", "k.a" this code is > > > working properly. > > > > > > Can anyone throw light on it? > > > > Hashes are not printable C strings. They are byte > > arrays. Thus, > > printf and strlen will both fail. > > > > -- > > Ken Goldman [EMAIL PROTECTED] 914-784-7646 > > > > > > > > __________________________________ > Do you Yahoo!? > Yahoo! Mail - You care about security. So do we. > http://promotions.yahoo.com/new_mail > ______________________________________________________________________ > OpenSSL Project http://www.openssl.org > User Support Mailing List openssl-users@openssl.org > Automated List Manager [EMAIL PROTECTED] > ______________________________________________________________________ OpenSSL Project http://www.openssl.org User Support Mailing List openssl-users@openssl.org Automated List Manager [EMAIL PROTECTED]