Debian Codegraph @

test_vectors/src/pbes2_botan.cpp

raw symbols SCIP
1 #include <botan/auto_rng.h>
2 #include <botan/ec_group.h>
3 #include <botan/ecdsa.h>
4 #include <botan/pkcs8.h>
5 #include <iostream>
6
7 #define array_size(arr) (sizeof(arr) / sizeof(*(arr)))
8
9 int main() {
10 try {
11 const std::string schemes[] = {
12 "PBE-PKCS5v20(AES-256/GCM,Scrypt)",
13 "PBE-PKCS5v20(AES-192/CBC,SHA-256)",
14 };
15 std::string password = "your_password";
16
17 // Generate an ECC key pair
18 Botan::AutoSeeded_RNG rng;
19 Botan::EC_Group ec_group("secp256r1");
20 Botan::ECDSA_PrivateKey private_key(rng, ec_group);
21
22 for (int i=0; i<array_size(schemes); i++) {
23
24 // Export the private key as PKCS#8 container encrypted with AES256-GCM
25 std::string encrypted_private_key =
26 Botan::PKCS8::PEM_encode(private_key, rng, password,
27 std::chrono::milliseconds(10), schemes[i]);
28
29 // Print the encrypted private key
30 std::cout << "Using scheme: " << schemes[i] << std::endl;
31 std::cout << "Encrypted Private Key:\n" << encrypted_private_key << std::endl;
32 }
33
34 return 0;
35 } catch (std::exception& e) {
36 std::cerr << "Error: " << e.what() << std::endl;
37 return 1;
38 }
39 }
40