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/examples/rsa_kgen.cpp | |
parent | 3d87bbc9edf36d5fa3ef6f827e88cb13d0fefcd3 (diff) |
Make a passphrase optional for the DSA and RSA key generation examples
Diffstat (limited to 'doc/examples/rsa_kgen.cpp')
-rw-r--r-- | doc/examples/rsa_kgen.cpp | 18 |
1 files changed, 11 insertions, 7 deletions
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; |