Make encrypt/decrypt more robust