我尝试导入证书的公钥以将其置于 ecc_key 结构中以供进一步使用。
为此,我在 wolfssl API 文档中找到了这个wc_EccPublicKeyDecode函数。我试图用它来将证书加载到 ecc_key 结构中。
const byte b64_cert[] = "MIIB6TCCAY+gAwIBAgIJAPhfFTGxGQMtMAoGCCqGSM49BAMCMFExCzAJBgNVBAYT"
"AlhYMQswCQYDVQQIDAJYWDELMAkGA1UEBwwCWFgxCzAJBgNVBAoMAlhYMQswCQYD"
"VQQLDAJYWDEOMAwGA1UEAwwFWFhYWFgwHhcNMTkwOTE4MTExMDQ3WhcNMjAwOTE3"
"MTExMDQ3WjBRMQswCQYDVQQGEwJYWDELMAkGA1UECAwCWFgxCzAJBgNVBAcMAlhY"
"MQswCQYDVQQKDAJYWDELMAkGA1UECwwCWFgxDjAMBgNVBAMMBVhYWFhYMFkwEwYH"
"KoZIzj0CAQYIKoZIzj0DAQcDQgAEOJdKmIL9KXUMcrR2obrUuyDsWoj7GFYxnGAI"
"wKz7aWgKenLL9pOTs5xhIkeZIEekkRayhV++CqMzEHRJhF6vNaNQME4wHQYDVR0O"
"BBYEFKtf9OtFyPb7GIkxjXsc8LbI6p4xMB8GA1UdIwQYMBaAFKtf9OtFyPb7GIkx"
"jXsc8LbI6p4xMAwGA1UdEwQFMAMBAf8wCgYIKoZIzj0EAwIDSAAwRQIhANN9YLSc"
"VcEQn/JEKcdPxdR70SnDkEa0hCrm3yiZqXSAAiB9krAmY/Shv2yq2sTD+84x7s9K"
"XcPcX00w1JyeaIbaDw==";
uint8_t der_cert[1000] = {0};
word32 size_of_cert = 1000;
ecc_key eccKey;
int wolfssl_ret = wc_ecc_init(&eccKey);
Base64_Decode(b64_cert, sizeof(b64_cert), der_cert, &size_of_cert);
word32 idx = 0;
wolfssl_ret = wc_EccPublicKeyDecode( der_cert, &idx, &eccKey, size_of_cert );
printf("wc_EccPublicKeyDecode failed! Wolfssl error = %d", wolfssl_ret);
但不幸的是,我总是收到 ASN_OBJECT_ID_E (-144) 错误代码:
wc_EccPublicKeyDecode failed! Wolfssl error = -144
那么我做错了什么?我使用了错误的功能吗?我还能如何将 DER/PEM 证书导入 ecc_key 结构?