I use openssl
in my C++ project, but a problem make me confused.
RSA *rsa = RSA_generate_key(kBits, kExp, 0, 0);
cout << "rsa->n: " << endl
<< rsa->n << endl
<< "rsa->d: " << endl
<< rsa->d << endl
<< "rsa->e: " << endl
<< rsa->e << endl;
char *n_b = BN_bn2hex(rsa->n);
char *d_b = BN_bn2hex(rsa->d);
char *e_b = BN_bn2hex(rsa->e);
n_s = std::string(n_b);
d_s = std::string(d_b);
e_s = std::string(e_b);
RSA *pRSAKey = RSA_new();
BN_hex2bn(&pRSAKey->n, n_s.c_str());
BN_hex2bn(&pRSAKey->d, d_s.c_str());
BN_hex2bn(&pRSAKey->e, e_s.c_str());
cout << "pRSAKey->n: " << endl
<< pRSAKey->n << endl
<< "pRSAKey->d: " << endl
<< pRSAKey->d << endl
<< "pRSAKey->e: " << endl
<< pRSAKey->e << endl;
To my surprise, the output are the following:
rsa->n:
0xee2200
rsa->d:
0xee2220
rsa->e:
0xee2240
pRSAKey->n:
0xee2fa0
pRSAKey->d:
0xee2fc0
pRSAKey->e:
0xee3390
So, Why does the value changed? What should I do to correct my code?