def METHOD_NAME(ownerObject, filepath, data):
    if ownerObject.hasEncryption and ownerObject.cipherKey is not None:
        cipher = AES.new(ownerObject.cipherKey, AES.MODE_EAX)
        if isinstance(data, str): # encode string into bytes
            bytesdata = data.encode("utf-8")
        else: # data is binary, doesn't need encoding
            bytesdata = data
        padlength = 16 - (len(bytesdata) % 16) # AES CBC padding
        bytesdata += padlength * (chr(padlength).encode())
        encrdata, tag = cipher.encrypt_and_digest(bytesdata)
        if isinstance(data, str): bytesdata = None # dereference before open operation
        with open(filepath + ENCRYPTED_FILE_SUFFIX, "wb") as fh:
            fh.write(cipher.nonce)
            fh.write(tag)
            fh.write(encrdata)
        return True # written successfully
    return None