如何将 OpenSSL SHA-512 哈希转换为 GMP 编号以在 RSA 加密方法中使用 [英] How to convert OpenSSL SHA-512 hash to GMP number to use in RSA encryption method

查看:75
本文介绍了如何将 OpenSSL SHA-512 哈希转换为 GMP 编号以在 RSA 加密方法中使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

encrypted 等于 0?我需要从这个散列中获取一个整数,以便我可以执行 RSA 加密.我在调试时看到散列,但似乎无法将其转换为 int.它是 SHA-512 所以 512 位?奇怪的字符来自 printf("%s",hash);atoi 也给出 0,我是否必须按字符分解散列?我认为那会奏效.

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 第二个参数必须是字符串.

mpz_set_str second parameter must be a string.

您传递给 SHA1 函数的 hash 参数可能不是字符串.将其转换为字符串格式,然后再将其传递给 mpz_set_str 函数.

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.

这篇关于如何将 OpenSSL SHA-512 哈希转换为 GMP 编号以在 RSA 加密方法中使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆