【发布时间】:2010-05-27 06:22:01
【问题描述】:
我有一个 DER 证书,我正在从中检索 unsigned char 缓冲区中的公钥,如下所示,这是正确的获取方式吗?
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? 或我可以使用以下???,
EVP_PKEY *d2i_PublicKey(int type, EVP_PKEY **a, unsigned char **pp, long length);
int i2d_PublicKey(EVP_PKEY *a, unsigned char **pp);
【问题讨论】:
标签: openssl