def AES(data, key, nonce, entype="AES_GCM", associated_data=None): if isinstance(data, str): data = data.encode("utf-8") if entype == "AES_GCM": aesgcm = AESGCM(key) if nonce is None: nonce = os.urandom(12) ct = aesgcm.encrypt(nonce, data, associated_data) return ct else: raise InvalidUsageException(10005)
def return_error(self, error_code, error_msg=None, status_code=400): raise InvalidUsageException(error_code, error_msg, status_code)
def generate_encryption_key(entype="AES_GCM", bit_length=128): if entype == "AES_GCM": key = AESGCM.generate_key(bit_length=bit_length) return key else: raise InvalidUsageException(10007)
def deAES(data, key, nonce, entype="AES_GCM", associated_data=None): if entype == "AES_GCM": aesgcm = AESGCM(key) return aesgcm.decrypt(nonce, data, associated_data) else: raise InvalidUsageException(10006)