Enhance the error handling of encryption/decryption