01 生成公钥和私钥

01 生成公钥和私钥

#include <botan/auto_rng.h>
<!--more-->
#include <botan/rsa.h>
#include <botan/pkcs8.h>
#include <botan/x509_key.h>

#include <iostream>

int main() {
try {
Botan::AutoSeeded_RNG rng;

// 生成 RSA 密钥对
Botan::RSA_PrivateKey private_key(rng, 2048); // 2048 是密钥位数,你可以根据需要调整
Botan::RSA_PublicKey public_key = private_key;

// 输出公钥和私钥
std::cout << "Public Key: " << Botan::X509::PEM_encode(public_key) << std::endl;
std::cout << "Private Key: " << Botan::PKCS8::PEM_encode(private_key) << std::endl;

}
catch (std::exception& e) {
std::cerr << "Error: " << e.what() << std::endl;
return 1;
}

return 0;
}