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

被刻印的时光 ゝ 提交于 2019-12-13 04:07:50

问题


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.


回答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.



来源:https://stackoverflow.com/questions/12772102/how-to-convert-openssl-sha-512-hash-to-gmp-number-to-use-in-rsa-encryption-metho

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!