X-Git-Url: http://git.datanom.net/securemail.git/blobdiff_plain/83a29369f877307549a84dd2a60bc242eca4be7e..462ce28c82250dc813e30999254e8bcbbfd4883d:/cryptonize.py diff --git a/cryptonize.py b/cryptonize.py index d24a72b..7a598d3 100644 --- a/cryptonize.py +++ b/cryptonize.py @@ -50,13 +50,21 @@ class Cryptonize: return plain def asymmetric_encrypt(self, privkey, pubkey, plain): + if not isinstance(plain, bytes): + plain = plain.encode('utf-8') box = Box(privkey, pubkey) - cipher = box.encrypt(plain) + if NACL_VERSION < "1.1.0": + nonce = random(Box.NONCE_SIZE) + cipher = box.encrypt(plain, nonce) + else: + cipher = box.encrypt(plain) box = None return cipher def asymmetric_decrypt(self, privkey, pubkey, cipher): + if not isinstance(cipher, bytes): + cipher = cipher.encode('utf-8') box = Box(privkey, pubkey) plain = box.decrypt(cipher) box = None