2017-04-17 3 views
0

Quelqu'un pourrait m'aider à trouver pourquoi je reçois un -16000 (mauvaises données d'entrée) sur tentative d'analyser une clé publique/privée à partir d'un char * non signé?mbedTLS pk parse erreur

Voici mon code (modifié par souci de concision):

DataPoint* GetPublicKey(mbedtls_pk_context* pppctx) 
{ 
    unsigned char* PKey = new unsigned char[16000]; 
    if (mbedtls_pk_write_pubkey_pem(pppctx, PKey, 16000) != 0) 
    { 
     delete[] PKey; 
     return NULL; 
    } 
    DataPoint* Out = new DataPoint(strlen((char*)PKey) + 1); //Initializes an internal unsigned char* and size_t with the length of the key and the null byte 
    memcpy(Out->Data, PKey, Out->Length); 
    delete[] PKey; 
    return Out; 
} 

void GenRSA(mbedtls_rsa_context* rs) 
{ 
    mbedtls_rsa_gen_key(rs, mbedtls_ctr_drbg_random, &dctx, 2048, 65537); 
} 

int main() 
{ 
    mbedtls_pk_context pctx; 
    mbedtls_pk_init(&pctx); 
    mbedtls_pk_setup(&pctx, mbedtls_pk_info_from_type(MBEDTLS_PK_RSA)); 

    DataPoint* Key = GetPublicKey(&some_context_with_GenRSA_called); 

    cout << mbedtls_pk_parse_public_key(&pctx, Key->Data, Key->Length) << endl; //Returns -16000 

    return 0 
} 

Et la même chose avec la clé privée, qu'est-ce que je fais mal?

Répondre