aboutsummaryrefslogtreecommitdiffstats
path: root/doc/examples/dsa_kgen.cpp
diff options
context:
space:
mode:
authorlloyd <[email protected]>2011-04-08 14:57:49 +0000
committerlloyd <[email protected]>2011-04-08 14:57:49 +0000
commitfc62f7f284387a180e42402e8706965a666efba7 (patch)
tree9abe74c670993c111bd3a5bf5fb568767f9e75be /doc/examples/dsa_kgen.cpp
parent438f3eb73e494fcab82b239452d712bec06f48c9 (diff)
More pubkey doc updates
Diffstat (limited to 'doc/examples/dsa_kgen.cpp')
-rw-r--r--doc/examples/dsa_kgen.cpp58
1 files changed, 58 insertions, 0 deletions
diff --git a/doc/examples/dsa_kgen.cpp b/doc/examples/dsa_kgen.cpp
new file mode 100644
index 000000000..fe3157370
--- /dev/null
+++ b/doc/examples/dsa_kgen.cpp
@@ -0,0 +1,58 @@
+/*
+* (C) 2009 Jack Lloyd
+*
+* Distributed under the terms of the Botan license
+*
+* Generate a 1024 bit DSA key and put it into a file. The public key
+* format is that specified by X.509, while the private key format is
+* PKCS #8.
+*/
+
+#include <iostream>
+#include <fstream>
+#include <string>
+#include <botan/botan.h>
+#include <botan/dsa.h>
+#include <botan/rng.h>
+using namespace Botan;
+
+#include <memory>
+
+int main(int argc, char* argv[])
+ {
+ if(argc != 1 && argc != 2)
+ {
+ std::cout << "Usage: " << argv[0] << " [passphrase]" << std::endl;
+ return 1;
+ }
+
+ Botan::LibraryInitializer init;
+
+ std::ofstream priv("dsapriv.pem");
+ std::ofstream pub("dsapub.pem");
+ if(!priv || !pub)
+ {
+ std::cout << "Couldn't write output files" << std::endl;
+ return 1;
+ }
+
+ try
+ {
+ AutoSeeded_RNG rng;
+
+ DL_Group group(rng, DL_Group::DSA_Kosherizer, 2048, 256);
+
+ DSA_PrivateKey key(rng, group);
+
+ pub << X509::PEM_encode(key);
+ if(argc == 1)
+ priv << PKCS8::PEM_encode(key);
+ else
+ priv << PKCS8::PEM_encode(key, rng, argv[1]);
+ }
+ catch(std::exception& e)
+ {
+ std::cout << "Exception caught: " << e.what() << std::endl;
+ }
+ return 0;
+ }