C SHA1 hash not working -


trying take character arracy (new c) , encode in sha1.

the following bit of code not working. returning '\x10'

char encode[1000]; strcpy(encode, "get\n\n\n"); strcat(encode, tim); strcat(encode, "\n"); strcat(encode, uri);  size_t length = sizeof(encode); unsigned char hash[sha_digest_length]; sha1(encode, length, hash);  return hash; 

at end of day, have base64 representation of hash. thanks!!!

most likely, problem you're returning locally declared memory lifetime equal function's scope. non-existent outside of scope. should allow user pass in buffer of own hold hash:

/* requires buffer size of @ least sha_digest_length bytes. */ void do_hash(unsigned char* buffer) {     /* code */     sha1(encode, length, buffer); } 

example of usage:

unsigned char* hash = malloc(sizeof(unsigned char) * sha_digest_length); do_hash(hash);  /* whatever want */  free(hash); 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -