diff options
author | lloyd <[email protected]> | 2009-08-13 08:49:29 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2009-08-13 08:49:29 +0000 |
commit | 8d078b50b7905080269ca8252477d37fdaed6db4 (patch) | |
tree | d2b607513e05872e42ae4b1e16b5051725220238 /doc/examples/cryptobox.cpp | |
parent | 240141b6df9c142c2046cea78043da4121e14333 (diff) |
Add a new interface CryptoBox which provides basic password-based encryption
in a reasonable way. Low on features, which is rather intentional. There
is a version code included in the format so further extensions are possible, if
warranted.
Inspired by the n-th mailing list request for such a class. Realized it was
probably better that I design such code than random people who just want
'something that works'.
Diffstat (limited to 'doc/examples/cryptobox.cpp')
-rw-r--r-- | doc/examples/cryptobox.cpp | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/doc/examples/cryptobox.cpp b/doc/examples/cryptobox.cpp new file mode 100644 index 000000000..0a769b0cd --- /dev/null +++ b/doc/examples/cryptobox.cpp @@ -0,0 +1,50 @@ +/* +* Cryptobox example +*/ +#include <botan/botan.h> +#include <botan/cryptobox.h> +#include <fstream> +#include <iostream> +#include <vector> + +using namespace Botan; + +int main(int argc, char* argv[]) + { + LibraryInitializer init; + + AutoSeeded_RNG rng; + + if(argc != 3) + { + std::cout << "Usage: cryptobox pass filename\n"; + return 1; + } + + std::string pass = argv[1]; + std::string filename = argv[2]; + + std::ifstream input(filename.c_str()); + + std::vector<byte> file_contents; + while(input.good()) + { + byte filebuf[4096] = { 0 }; + input.read((char*)filebuf, sizeof(filebuf)); + size_t got = input.gcount(); + + file_contents.insert(file_contents.end(), filebuf, filebuf+got); + } + + std::string ciphertext = CryptoBox::encrypt(&file_contents[0], + file_contents.size(), + pass, rng); + + std::cout << ciphertext; + + /* + std::cout << CryptoBox::decrypt((const byte*)&ciphertext[0], + ciphertext.length(), + pass); + */ + } |