1

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

ここに画像の説明を入力

4

1 に答える 1

0

答えが見つかりました、返信ありがとうございます。

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;
}
于 2013-01-28T15:32:22.657 に答える