diff options
author | lloyd <[email protected]> | 2006-09-04 07:15:41 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2006-09-04 07:15:41 +0000 |
commit | 6fed1b3a9649e4f7d74184305c543994f344999a (patch) | |
tree | 70da00fb4e92056efe12ff18f0c18a8ed40969b8 /doc | |
parent | 3d87bbc9edf36d5fa3ef6f827e88cb13d0fefcd3 (diff) |
Make a passphrase optional for the DSA and RSA key generation examples
Diffstat (limited to 'doc')
-rw-r--r-- | doc/examples/dsa_kgen.cpp | 11 | ||||
-rw-r--r-- | doc/examples/rsa_kgen.cpp | 18 |
2 files changed, 17 insertions, 12 deletions
diff --git a/doc/examples/dsa_kgen.cpp b/doc/examples/dsa_kgen.cpp index eb3a00393..2e42c06b7 100644 --- a/doc/examples/dsa_kgen.cpp +++ b/doc/examples/dsa_kgen.cpp @@ -25,14 +25,12 @@ using namespace Botan; int main(int argc, char* argv[]) { - if(argc != 2) + if(argc != 1 && argc != 2) { - std::cout << "Usage: " << argv[0] << " passphrase" << std::endl; + std::cout << "Usage: " << argv[0] << " [passphrase]" << std::endl; return 1; } - std::string passphrase(argv[1]); - std::ofstream priv("dsapriv.pem"); std::ofstream pub("dsapub.pem"); if(!priv || !pub) @@ -47,7 +45,10 @@ int main(int argc, char* argv[]) DSA_PrivateKey key(DL_Group("dsa/jce/1024")); pub << X509::PEM_encode(key); - priv << PKCS8::PEM_encode(key, passphrase); + if(argc == 1) + priv << PKCS8::PEM_encode(key); + else + priv << PKCS8::PEM_encode(key, argv[1]); } catch(std::exception& e) { diff --git a/doc/examples/rsa_kgen.cpp b/doc/examples/rsa_kgen.cpp index f2601101e..210eca52c 100644 --- a/doc/examples/rsa_kgen.cpp +++ b/doc/examples/rsa_kgen.cpp @@ -18,9 +18,10 @@ using namespace Botan; int main(int argc, char* argv[]) { - if(argc != 3) + if(argc != 2 && argc != 3) { - std::cout << "Usage: " << argv[0] << " bitsize passphrase" << std::endl; + std::cout << "Usage: " << argv[0] << " bitsize [passphrase]" + << std::endl; return 1; } @@ -31,8 +32,6 @@ int main(int argc, char* argv[]) return 1; } - std::string passphrase(argv[2]); - std::ofstream pub("rsapub.pem"); std::ofstream priv("rsapriv.pem"); if(!priv || !pub) @@ -41,12 +40,17 @@ int main(int argc, char* argv[]) return 1; } - try { + try + { LibraryInitializer init; RSA_PrivateKey key(bits); pub << X509::PEM_encode(key); - priv << PKCS8::PEM_encode(key, passphrase); - } + + if(argc == 2) + priv << PKCS8::PEM_encode(key); + else + priv << PKCS8::PEM_encode(key, argv[2]); + } catch(std::exception& e) { std::cout << "Exception caught: " << e.what() << std::endl; |