Serialization helpers for encryption and compression