使用openssl 1.0.1.16(diffi-hellman)生成公钥和私钥

时间:2018-09-17 10:15:55

标签: c++

我想使用Openssl 1.0.1.16(diffi hellman算法)生成公钥和私钥。 我在解决方案中添加了C ++头文件(dll)。 我有p(素数)和g(发电机)值。我必须使用p和g生成密钥。 我初始化了p和g值,并调用了DH_generate_key(dh)方法,但没有得到1024位/ 128字节。

以下是我的代码段。

 const char *prime  = ""; //256 hexa string
const char *gen = "0x5";//hexa format 
const char *publickKey ;
DH *dh =DH_new();
BN_hex2bn(&(dh->DH::p), prime);
BN_hex2bn(&(dh->DH::g), gen);
// Generate public and private keys
if(DH_generate_key(dh)==1)
{
publickKey=BN_bn2hex((dh->pub_key));
}

我得到以下输出: dh-> pub_key 0x00a770e0 {d = 0x00a76cc8 top = 0 dmax = 32 ...}     d:0x00a76cc8     最高:0     dmax:32     负数:0     标志:1 dh-> priv_key 0x00a78fe8 {d = 0x00a769b8 top = 32 dmax = 32 ...}     d:0x00a769b8     最高:32     dmax:32     负数:0     标志:1 但我希望1024位和256个字符长度。

请根据我的要求帮助我生成密钥对。

谢谢

0 个答案:

没有答案