aboutsummaryrefslogtreecommitdiffstats
path: root/src/cmd/keygen.cpp
diff options
context:
space:
mode:
authorlloyd <[email protected]>2014-01-10 00:08:13 +0000
committerlloyd <[email protected]>2014-01-10 00:08:13 +0000
commit57789bdfc55061002b2727d0b32587612829a37c (patch)
tree99f36631b4ec50c5187a1b0a7c256b99182373ad /src/cmd/keygen.cpp
parent94968c917407a63d888fd3eb4d02491f60de6ebc (diff)
Split up test vectors into per-algo files and app into botan-test for
the tests and botan for everything else.
Diffstat (limited to 'src/cmd/keygen.cpp')
-rw-r--r--src/cmd/keygen.cpp53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/cmd/keygen.cpp b/src/cmd/keygen.cpp
new file mode 100644
index 000000000..40055f6cf
--- /dev/null
+++ b/src/cmd/keygen.cpp
@@ -0,0 +1,53 @@
+#include "apps.h"
+#include <iostream>
+#include <fstream>
+#include <string>
+#include <cstdlib>
+#include <memory>
+
+#include <botan/rsa.h>
+using namespace Botan;
+
+int keygen_main(int argc, char* argv[])
+ {
+ if(argc != 2 && argc != 3)
+ {
+ std::cout << "Usage: " << argv[0] << " bitsize [passphrase]"
+ << std::endl;
+ return 1;
+ }
+
+ const size_t bits = std::atoi(argv[1]);
+ if(bits < 1024 || bits > 16384)
+ {
+ std::cout << "Invalid argument for bitsize" << std::endl;
+ return 1;
+ }
+
+ try
+ {
+ std::ofstream pub("rsapub.pem");
+ std::ofstream priv("rsapriv.pem");
+ if(!priv || !pub)
+ {
+ std::cout << "Couldn't write output files" << std::endl;
+ return 1;
+ }
+
+ AutoSeeded_RNG rng;
+
+ RSA_PrivateKey key(rng, bits);
+ pub << X509::PEM_encode(key);
+
+ if(argc == 2)
+ priv << PKCS8::PEM_encode(key);
+ else
+ priv << PKCS8::PEM_encode(key, rng, argv[2]);
+ }
+ catch(std::exception& e)
+ {
+ std::cout << "Exception caught: " << e.what() << std::endl;
+ }
+
+ return 0;
+ }