Topic: Wolfssl cannot decode ECC private key generated by openssl
Hi all,
I am having a hard time to decode a ecc private key with wolfssl.
Here how my key must be generated (It has to be this way, it is a requirement)
openssl ecparam -genkey -name prime256v1 -noout -out ec_private.pem
openssl ec -in ec_private.pem -pubout -out ec_public.pem
const char* private_key_pem = private_key_data->crypto_key_union.key_pem.key;
output private key:
-----BEGIN EC PRIVATE KEY-----
MHcCAQEEIB9OmcdEpovFHYwrKwb/0LAShWskWY8GJbEz8zRDmNdzoAoGCCqGSM49
AwEHoUQDQgAEj89fqBfGJRtV37F6+peeEwNbQx5D5NnkoFJPyfE54UAWKM+6zTc/
EZQ6egk/k8Kh+VYJE+bak9x8Qo45yrZelw==
-----END EC PRIVATE KEY-----
DerBuffer* pDer = NULL;
ret = PemToDer((unsigned char*)private_key_pem, strlen(private_key_pem),
ECC_PRIVATEKEY_TYPE, &pDer, NULL, NULL, NULL);
decode to DER format:
307702010104201f4e99c744a68bc51d8c2b2b06ffd0b012856b24598f0625b133f3344
398d773a00a06082a8648ce3d030107a144034200048fcf5fa817c6251b55dfb17afa97
9e13035b431e43e4d9e4a0524fc9f139e1401628cfbacd373f11943a7a093f93c2a1f95
60913e6da93dc7c428e39cab65e97
then decode the private key to be stored into the structure:
ecc_key ecc_key_private;
wc_ecc_init(&ecc_key_private);
word32 in_out_idx = 0;
ret = wc_EccPrivateKeyDecode(pDer->buffer, &in_out_idx, &ecc_key_private,
pDer->length);
the error is here= -140 => ASN Parsing error.
Can anyone help me?
wolfssl version: 4.7.0-stable
Thanks
Remy