Encrypt an Object
Problem
You want to use encryption on an entire object, not just individual pieces of data.
Solution
Use .NET serialization to convert the object to a stream of bytes, and encrypt the serialized data.
Discussion
Recipes Serialize an Object to Disk, Serialize Public Members of a Nonserializable Object, and Perform Selective Serialization with the Memento Pattern demonstrated different ways to serialize an object to a stream of bytes. You can use this technique in conjunction with symmetric or asymmetric encryption to encrypt the contents of a serializable object. If you’re using asymmetric encryption, you’ll need to convert the object to an array of bytes and then encrypt these bytes one block at a time. If you’re using symmetric encryption, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access