2

We have a Go app that generates an RSA key and sends the public key to the client in PKCS #1, ASN.1 DER form.

https://golang.org/pkg/crypto/x509/#MarshalPKCS1PublicKey

When I try to load the same public key in the c++ client using Botan 1.10.17:

try
{
    Botan::AutoSeeded_RNG rng;
    Botan::DataSource_Memory pubKeyMem(publicKey); // here public key is in PKCS #1, ASN.1 DER form
    Botan::RSA_PublicKey *rsaKey = dynamic_cast<Botan::RSA_PublicKey*>(Botan::X509::load_key(pubKeyMem));
    ...
}
catch (std::exception& e)
{
    cout << e.what();
}

I get an exception:

Decoding error: X.509 public key decoding failed

Here is the public key generated by the server:

-----BEGIN RSA PUBLIC KEY-----
MIIBCgKCAQEA80s5aG/cuYU/xT3WsC5FkJmMdCg1SFFuc+qJT8aB1IgR3mnKGARf
tKpZ3Uk8Ehp1PSgS+tJE+NhE5fjU8S2K9EtGbep4DAK/TmeJ1TQvJXtCcrMH7MFV
Ck57X972MChnR5wJYrCnBYXt4Q9f76AT4PfFHCgN+eePYD175VIUN7rZlqZaqgX4
LAWQQpZsrj1DersOeH6YfMeuXplTljePGlKcutvWtr3LqGSAkPKAngW3gGTNcxXh
s8EW0CxXctvPLuWArlV2afU6XIpqWGVxB3NlRVuU64XvOE+aXyL2LyX2DXCWzzs8
mKjwp4SQW2xiJiQoRy3gmAR8oV8Jgffs2wIDAQAB
-----END RSA PUBLIC KEY-----
Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
adnan kamili
  • 8,967
  • 7
  • 65
  • 125

1 Answers1

1

It seems Botan 1.10.17 expects the public key in the PKIX, ASN.1 DER form. So using x509.MarshalPKIXPublicKey() instead of x509.MarshalPKCS1PublicKey() in Golang made the C++ Botan client work.

adnan kamili
  • 8,967
  • 7
  • 65
  • 125