我正在使用OpenSSL生成私有密钥,公共密钥和共享密钥。 我能够生成公钥和私钥。这里的问题是我能够在未签名的字符中生成共享密钥,例如“ ¦,¢þxìÈ€-Sbª»µèèMÞ¡ŒuÛk5wDØ.ÖÜ J÷¦ |«ë²ã&³。”。 ¼k™>ÅW#üPfóˆÚÂÒÏäˆåUࡽ#›E§Ü‹¸#] 9r!³A^'D |ƒWvÒ“
如何将其转换为十六进制或大数字?
以下是我的代码段。
const char *prime = "7ec3adc389044fcb86c3b6c3b23fc3915b6dc388c3a7c2a9c2bdc3953cc2bfc2b764e280a1c388c2bac3abc388c3b7070915c3b13941c2bec2aac39660c2bc251e110fc38b625f1c5979c2a026c39ac5a00f18e280bae2809913c3bb9c39e6555cc3565656b9c3ac6ac2abc2be28c2b10161c2b02775c3bbc380c3bd4438c3b5";
const char *generator = "5";
const char *serverPubKey ="73491FD2EDFB73FCEB6D6C0169C78816956AAA9A2E71B33C23296CEE8255FCAC83A6601E40A62E5E24D9FE1E821B2D25BEE8EBC5F41C73ABC95A9678890EF07F2581B20454F390ADB97415305B89932BD5D21A19C1867A89922E019515F76524B317E40BC0479B727F367F38C620F37FE5D7A6FF76DA36D6065F804FC5605051";
DH *dh;
dh= DH_new();
// Initialize dh's generator and prime
BN_hex2bn(&(dh->g), generator);
BN_hex2bn(&(dh->p), prime);
// Generate public and private keys
DH_generate_key(dh);
BIGNUM *server_pub_key = BN_new();
BN_hex2bn(&server_pub_key, serverPubKey);
// Use DH to calculate the shared key
vector<char> shared_key;
int est_size = DH_size(dh);
shared_key.resize( est_size );
int actual_size = DH_compute_key( (unsigned char*)&shared_key.front(), server_pub_key, dh );
谢谢。