繁体   English   中英

openssl c ++需要以十六进制格式显示公钥

[英]openssl c++ need to display public key in hex format

我可以使用一些帮助,我需要显示公钥,就像Windows双击证书时一样(参见图片)。 谢谢。

我可以通过以下任一方式获取公钥:

RSA * pubKey = X509_get_pubkey(csc-> current_cert)-> pkey.rsa;

要么

EVP_PKEY * pubKey = X509_get_pubkey(csc-> current_cert);

如果在某处找到此代码段,但获得的值与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;
    }
}

在此处输入图片说明

我找到了答案,谢谢您的答复。

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;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM