当前位置: 首页>>代码示例>>C++>>正文


C++ PANSC_ASN1_CERTIFICATE::ExportPublicKey方法代码示例

本文整理汇总了C++中PANSC_ASN1_CERTIFICATE::ExportPublicKey方法的典型用法代码示例。如果您正苦于以下问题:C++ PANSC_ASN1_CERTIFICATE::ExportPublicKey方法的具体用法?C++ PANSC_ASN1_CERTIFICATE::ExportPublicKey怎么用?C++ PANSC_ASN1_CERTIFICATE::ExportPublicKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PANSC_ASN1_CERTIFICATE的用法示例。


在下文中一共展示了PANSC_ASN1_CERTIFICATE::ExportPublicKey方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: AnscTrace

/*************************************************************************
 *
 * This is the api to init the KeyGenParams from the given certificate
 * and private key info
 *
 *************************************************************************/
ANSC_STATUS
PKIUtilityInitKeyGenParams
    (
        ANSC_HANDLE                         hSSLCrypto,
        PANSC_ASN1_CERTIFICATE              pCert,
        PANSC_ASN1_PRIVATEKEYINFO           pKeyInfo,
        ANSC_HANDLE                         hKeyGenParams
    )
{
    PANSC_CRYPTO_PUB_KEY_GEN_PARAMS         pKeyGenParams = (PANSC_CRYPTO_PUB_KEY_GEN_PARAMS)hKeyGenParams;
    PANSC_CRYPTO_PUB_SSLEAY_OBJECT          pSSLCrypto    = (PANSC_CRYPTO_PUB_SSLEAY_OBJECT)hSSLCrypto;
    BOOLEAN                                 bKeyPair      = TRUE;
    PKI_KEY_TYPE                            keyType;

    if( pCert == NULL || pKeyInfo == NULL || hKeyGenParams == NULL)
    {
        return ANSC_STATUS_FAILURE;
    }

    keyType = pCert->GetKeyType(pCert);

    if( keyType != PKI_RSA_KEY && keyType != PKI_DSA_KEY)
    {
        return ANSC_STATUS_FAILURE;
    }

    if( keyType != pKeyInfo->GetKeyType(pKeyInfo))
    {
        AnscTrace("The key pair  is not in the same key type.\n");

        return ANSC_STATUS_FAILURE;
    }

    /* init the public key */
    if( ANSC_STATUS_SUCCESS != 
            pCert->ExportPublicKey
                (
                    pCert,
                    hKeyGenParams
                ))
    {
        return ANSC_STATUS_FAILURE;
    }

    /* init the private key */
    if( ANSC_STATUS_SUCCESS !=
            pKeyInfo->ExportKey
                (
                    pKeyInfo,
                    hKeyGenParams
                ))
    {
        return ANSC_STATUS_FAILURE;
    }

    /* verify the key pair */
    if( pSSLCrypto != NULL)
    {
        if( keyType == PKI_RSA_KEY)
        {
            bKeyPair = 
                pSSLCrypto->KeyPairMatch
                    (
                        pSSLCrypto,
                        ANSC_CRYPTO_PUB_KEY_RSA,
                        &pKeyGenParams->PublicKey.RSA,
                        &pKeyGenParams->PrivateKey.RSA
                    );
        }
        else
        {
            bKeyPair = 
                pSSLCrypto->KeyPairMatch
                    (
                        pSSLCrypto,
                        ANSC_CRYPTO_PUB_KEY_DSA,
                        &pKeyGenParams->PublicKey.DSA,
                        &pKeyGenParams->PrivateKey.DSA
                    );
        }
    }

    if( bKeyPair)
    {
        return ANSC_STATUS_SUCCESS;
    }
    else
    {
        return ANSC_STATUS_FAILURE;
    }
}
开发者ID:davekimble,项目名称:CcspCommonLibrary,代码行数:97,代码来源:pki_utility_api.c

示例2: if

ANSC_X509_KEY*
AnscX509CertGetPublicKey
    (
        void*                       raw_cert_data,
        ULONG                       raw_cert_size
    )
{
    PANSC_ASN1_CERTIFICATE          pAsnCert        = NULL;
    ANSC_X509_KEY*                  pX509Key        = NULL;
    PANSC_CRYPTO_PUB_KEY_GEN_PARAMS pGenParams;

    /* decode the asn.1 certificate handle */
    pAsnCert = (PANSC_ASN1_CERTIFICATE)
        anscGetCertHandle
            (
                raw_cert_data,
                raw_cert_size
            );

    if( pAsnCert == NULL)
    {
        goto EXIT;
    }

    /* export the public key */
    pGenParams = (PANSC_CRYPTO_PUB_KEY_GEN_PARAMS)
        AnscAllocateMemory(sizeof(ANSC_CRYPTO_PUB_KEY_GEN_PARAMS));

    if( pGenParams == NULL)
    {
        goto EXIT;
    }

    if( ANSC_STATUS_SUCCESS !=
            pAsnCert->ExportPublicKey(pAsnCert, pGenParams))
    {
        AnscFreeMemory(pGenParams);

        goto EXIT;
    }

    /* create the X509_KEY */
    pX509Key = (PANSC_X509_KEY)AnscAllocateMemory(sizeof(ANSC_X509_KEY));

    if( pX509Key == NULL)
    {
        AnscFreeMemory(pGenParams);

        goto EXIT;
    }

    pX509Key->KeySize       = sizeof(ANSC_CRYPTO_PUB_KEY_GEN_PARAMS);
    pX509Key->KeyData       = (void*)pGenParams;

    if( pAsnCert->GetKeyType(pAsnCert) == PKI_RSA_KEY)
    {
        pX509Key->KeyType          = ANSC_CERT_keyType_rsa;
    }
    else if( pAsnCert->GetKeyType(pAsnCert) == PKI_DSA_KEY)
    {
        pX509Key->KeyType          = ANSC_CERT_keyType_dsa;
    }

    pX509Key->KeyBits              = pAsnCert->GetKeyBits(pAsnCert);

EXIT:

    anscFreeCertHandle((ANSC_HANDLE)pAsnCert);

    return pX509Key;
}
开发者ID:rdkcmf,项目名称:rdkb-CcspCommonLibrary,代码行数:71,代码来源:ansc_x509_cert.c


注:本文中的PANSC_ASN1_CERTIFICATE::ExportPublicKey方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。