EVP_PKEY from char buffer in x509 (PKCS7)

前端 未结 2 1522
忘掉有多难
忘掉有多难 2021-01-03 09:30

I have a DER certificate from which I am retrieving the Public key in unsigned char buffer as following, is it the right way of getting?

pStoredPublicKey =          


        
2条回答
  •  情话喂你
    2021-01-03 09:36

    The following openssl API works for unsigned char buffer to EVP_PKEY,

    EVP_PKEY *d2i_PublicKey(int type, EVP_PKEY **a, unsigned char **pp, long length);
    int i2d_PublicKey(EVP_PKEY *a, unsigned char **pp);
    

    And, the following works for Convert EVP_PKEY to unsigned char buffer.

    int pkeyLen;
    unsigned char *ucBuf, *uctempBuf;
    pkeyLen = i2d_PublicKey(pkey, NULL);
    ucBuf = (unsigned char *)malloc(pkeyLen+1);
    uctempBuf = ucBuf;
    i2d_PublicKey(pkey, &uctempBuf);
    int ii;
    for (ii = 0; ii < pkeyLen; ii++)
    {
            printf("%02x\n", (unsigned char) ucBuf[ii]);
    }
    

    Thanks-opensid

提交回复
热议问题