skey = self.sanitize_key(key)
box = SecretBox(skey)
if NACL_VERSION < "1.1.0":
- from nacl.utils import random
- from nacl.public import SecretBox
nonce = random(SecretBox.NONCE_SIZE)
cipher = box.encrypt(plain, nonce)
else:
def asymmetric_encrypt(self, privkey, pubkey, plain):
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