How to convert OpenSSL SHA-512 hash to GMP number to use in RSA encryption method

StackOverflow https://stackoverflow.com/questions/12772102

  •  05-07-2021
  •  | 
  •  

문제

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.

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top