Encrypt and decrypt data with a given key.