【问题标题】:openssl c++ need to display public key in hex formatopenssl c++需要以十六进制格式显示公钥
【发布时间】: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


【解决方案1】:

找到答案了,谢谢回复。

ASN1_BIT_STRING *pubKey = X509_get0_pubkey_bitstr(csc->current_cert); // csc->current_cert is an X509 struct

for (int i = 0; i < pubKey->length; i++)
{
    CString str;
    if( 0 == i )
        str.Format( L"%02X", pubKey->data[i] );
    else
        str.Format( L" %02X", pubKey->data[i] );

    PubKey += str;
}

【讨论】:

    猜你喜欢
    • 2015-12-23
    • 1970-01-01
    • 1970-01-01
    • 2011-04-21
    • 1970-01-01
    • 2019-09-28
    • 2010-12-09
    • 1970-01-01
    • 2010-10-15
    相关资源
    最近更新 更多