TPMT_PUBLIC Serialize to other Format file?

116 views Asked by At

[a similar questions link][1] [1]: https://stackoverflow.com/questions/60340870/serialize-tpm-public-key-to-der-or-pem

But,I don't Know how to do that,using botan to covert data. TPMT_PUBLIC ===> PEM

1

There are 1 answers

0
帅是理 On BEST ANSWER
TPMS_RSA_PARMS *rsaParms = dynamic_cast<TPMS_RSA_PARMS*>(&*persistentPub.outPublic.parameters);
if (rsaParms == NULL)
{
    throw domain_error("Only RSA encryption is supported");
}

TPM2B_PUBLIC_KEY_RSA *rsaPubKey = dynamic_cast<TPM2B_PUBLIC_KEY_RSA*>(&*persistentPub.outPublic.unique);

    auto rsaPublicKey = Botan::RSA_PublicKey(Botan::BigInt(rsaPubKey->buffer.data(), rsaPubKey->buffer.size()), rsaParms->exponent);
    std::string strPemText = Botan::X509::PEM_encode(rsaPublicKey);
    cout << "public format Text:  " << strPemText.c_str() << endl;