aboutsummaryrefslogtreecommitdiffstats
path: root/doc/python/cryptobox.py
diff options
context:
space:
mode:
Diffstat (limited to 'doc/python/cryptobox.py')
-rwxr-xr-xdoc/python/cryptobox.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/doc/python/cryptobox.py b/doc/python/cryptobox.py
new file mode 100755
index 000000000..1968b40e1
--- /dev/null
+++ b/doc/python/cryptobox.py
@@ -0,0 +1,34 @@
+#!/usr/bin/python
+
+import sys
+import botan
+
+def main(args = None):
+ if args is None:
+ args = sys.argv
+
+ if len(args) != 3:
+ raise Exception("Bad usage")
+
+ password = args[1]
+ input = ''.join(open(args[2]).readlines())
+
+ rng = botan.RandomNumberGenerator()
+
+ ciphertext = botan.cryptobox_encrypt(input, password, rng)
+
+ print ciphertext
+
+ plaintext = ''
+
+ try:
+ plaintext = botan.cryptobox_decrypt(ciphertext, password + 'FAIL')
+ except Exception, e:
+ print "Oops -- ", e
+
+ plaintext = botan.cryptobox_decrypt(ciphertext, password)
+
+ print plaintext
+
+if __name__ == '__main__':
+ sys.exit(main())