PrevUpHomeNext

RSA Key - Botan Utxcpp


Botan RSA Keys

Create Botan Public Key:

Botan::X509::PEM_encode

Create Botan Private Key:

Botan::PKCS8::PEM_encode

(utx::print) (utx::string)

c++ example

[Note] Note

Copyright (c) 2023 Fas Xmut (fasxmut at protonmail dot com)

Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#include <utxcpp/core.hpp>
#include <botan/auto_rng.h>
#include <botan/rsa.h>
#include <botan/x509_key.h>
#include <botan/pkcs8.h>

int main()
{
	Botan::AutoSeeded_RNG rng;
	Botan::RSA_PrivateKey key{rng, 2048};
	// utx::string constructor accepts std::string
	utx::string public_key = Botan::X509::PEM_encode(key);
	utx::string private_key = Botan::PKCS8::PEM_encode(key, rng, "123"); // password: 123
	utx::print("public key:\n\n", public_key);
	utx::print("private key:\n\n", private_key);
}

Output

One possible output:

public key:

-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAn1e2vsPlHUHcy9IstNmH
lRnDqQekaXedoI5lvmsXW7Xu3O4YAgvAgbUWPnXnvoUL+FzoO6tuwd7IaTZnk+wf
wmLzzZ6uaURfUIPSgrPudxrAMToVUajjvorNLZI3RQpAhLG7BeQj9+C+lm4zhjQj
BF15yHwcJUHKJsZSr4AoOAOPZ7RRYyX+aLltZLkaxobuIlK0wb4OHDUiXO8i80WN
xqjMco/iDxU0e5AA655bMGKpitOSTEfODYrI0gPiyC7mItE+u3CvVSuh8i7Drg0J
WJCXDIFLWak3PipgCbmjYmVlb7L13A7wc78fGOhHYSsxGSlNVRNas0ckS4jnFGQp
iQIDAQAB
-----END PUBLIC KEY-----

private key:

-----BEGIN ENCRYPTED PRIVATE KEY-----
MIIFNTBfBgkqhkiG9w0BBQ0wUjAxBgkqhkiG9w0BBQwwJAQMc+lV8VNyUKoaN7BW
AgMDuSACASAwDAYIKoZIhvcNAgkFADAdBglghkgBZQME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