2
我有一个DER证书,我从中检索公钥在无符号字符缓冲区如下,它是正确的方式获取?从字符缓冲区x509(PKCS7)EVP_PKEY
pStoredPublicKey = X509_get_pubkey(x509);
if(pStoredPublicKey == NULL)
{
printf(": publicKey is NULL\n");
}
if(pStoredPublicKey->type == EVP_PKEY_RSA) {
RSA *x = pStoredPublicKey->pkey.rsa;
bn = x->n;
}
else if(pStoredPublicKey->type == EVP_PKEY_DSA) {
}
else if(pStoredPublicKey->type == EVP_PKEY_EC) {
}
else {
printf(" : Unkown publicKey\n");
}
//extracts the bytes from public key & convert into unsigned char buffer
buf_len = (size_t) BN_num_bytes (bn);
key = (unsigned char *)malloc (buf_len);
n = BN_bn2bin (bn, (unsigned char *) key);
for (i = 0; i < n; i++)
{
printf("%02x\n", (unsigned char) key[i]);
}
keyLen = EVP_PKEY_size(pStoredPublicKey);
EVP_PKEY_free(pStoredPublicKey);
,与此无符号的字符缓冲区,如何获得回来RSA的EVP_PKEY? OR我可以透过以下???,
EVP_PKEY *d2i_PublicKey(int type, EVP_PKEY **a, unsigned char **pp, long length);
int i2d_PublicKey(EVP_PKEY *a, unsigned char **pp);