0
SHA1(data, length, hash);
unsigned char *labelPtr;

labelPtr = hash;
mpz_set_str (encrypted, labelPtr, 16);
gmp_printf("hashed= %Zd\n", encrypted);

encrypted equals 0? I need to get an integer from this hash so that I can perform RSA encryption. I see the hash when I debug, but cannot seem to turn this into an int. It is SHA-512 so 512 bits? Weird characters come out of printf("%s",hash); atoi gives 0 too, do I have to break up the hash by character? That would work I think.

Gandaro
  • 3,427
  • 1
  • 17
  • 19
csestony
  • 215
  • 2
  • 12

1 Answers1

1

mpz_set_str second parameter must be a string.

The hash argument you pass to SHA1 function is probably not a string. Convert it to a string format before passing it to the mpz_set_str function.

ouah
  • 142,963
  • 15
  • 272
  • 331
  • \355\020\ is the value in the hash after – csestony Oct 07 '12 at 19:47
  • if i use print f wierd characters come out printf("%s",hash); so im sure its a string... just very wierd atoi gives 0 too, do i have to break up the hash by character because that would work i think – csestony Oct 07 '12 at 19:48
  • @Thefirstkilla `mpz_set_str (encrypted, labelPtr, 16)` requires you to have a string and basis 16 to be used. Your string should be printable: you have to convert your array to a string with basis 16 values. You can use `sprintf` to do that. – ouah Oct 07 '12 at 19:57