aboutsummaryrefslogtreecommitdiffstats
path: root/doc/python/cipher.py
diff options
context:
space:
mode:
authorlloyd <[email protected]>2009-10-13 16:01:57 +0000
committerlloyd <[email protected]>2009-10-13 16:01:57 +0000
commit9268a0455a07d31a66364aa5b7594bd75250b466 (patch)
tree63b683ca95448ce083981d002d870a569c2c98a1 /doc/python/cipher.py
parent3bc2bb0461b1b40466821daf0061eab769621eab (diff)
parent5318b944acc2a5fa6d445784c710f37c793ff90b (diff)
propagate from branch 'net.randombit.botan.1_8' (head c5ae189464f6ef16e3ce73ea7c563412460d76a3)
to branch 'net.randombit.botan' (head e2b95b6ad31c7539cf9ac0ebddb1d80bf63b5b21)
Diffstat (limited to 'doc/python/cipher.py')
-rwxr-xr-xdoc/python/cipher.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/doc/python/cipher.py b/doc/python/cipher.py
new file mode 100755
index 000000000..1be2759ae
--- /dev/null
+++ b/doc/python/cipher.py
@@ -0,0 +1,44 @@
+#!/usr/bin/python
+
+import botan
+import sys
+
+def encrypt(input, passphrase):
+ rng = botan.RandomNumberGenerator()
+
+ # Use as both EAX IV and PBKDF2 salt
+ salt = rng.gen_random(10)
+
+ iterations = 10000
+ output_size = 16
+
+ key = botan.pbkdf2(passphrase, salt, iterations, output_size, "SHA-1")
+
+ encryptor = botan.Cipher("AES-128/EAX", "encrypt", key)
+
+ ciphertext = encryptor.cipher(input, salt)
+ return (ciphertext, salt)
+
+def decrypt(input, salt, passphrase):
+ iterations = 10000
+ output_size = 16
+
+ key = botan.pbkdf2(passphrase, salt, iterations, output_size, "SHA-1")
+
+ decryptor = botan.Cipher("AES-128/EAX", "decrypt", key)
+
+ return decryptor.cipher(input, salt)
+
+def main(args = None):
+ if args is None:
+ args = sys.argv
+
+ passphrase = args[1]
+ input = ''.join(open(args[2]).readlines())
+
+ (ciphertext, salt) = encrypt(input, passphrase)
+
+ print decrypt(ciphertext, salt, passphrase)
+
+if __name__ == '__main__':
+ sys.exit(main())