【发布时间】:2013-01-09 21:02:48
【问题描述】:
我需要一些帮助,我需要显示一个公钥,就像 Windows 在双击证书时一样(见图)。谢谢。
我可以通过以下任一方式获取公钥:
RSA *pubKey = X509_get_pubkey(csc->current_cert)->pkey.rsa;
或
EVP_PKEY *pubKey = X509_get_pubkey(csc->current_cert);
如果在某处找到这个 sn-p 但我得到的值与 Windows 显示的不同:
unsigned char enc_bin[1024] = {0};
int enc_len = 0;
unsigned char dec_bin[1024] = {0};
int dec_len = 0;
enc_len = RSA_size( pubKey );
memset( enc_bin, 1, enc_len );
if( 0 < ( dec_len = RSA_public_decrypt( enc_len, enc_bin, dec_bin, pubKey, RSA_NO_PADDING) ) )
{
for (int i = 0; i < dec_len; i++)
{
CString str;
if( 0 == i )
str.Format( L"%02X", dec_bin[i] );
else
str.Format( L" %02X", dec_bin[i] );
PubKey += str;
}
}
【问题讨论】:
-
看起来您打印的是解密的文本,而不是键值本身。
-
我尝试在解密之前打印 pubKey 的 BigNum 数据,但我仍然得到了与上面显示的不同的字节集。我应该在 pubKey 中查看其他数据吗?谢谢。
标签: c++ openssl public-key