Encrypting Objects
Sometimes, you might want to encrypt a Java object and write it to a file or send it over a network. Although you could combine the ObjectOutputStream class with CipherOutputStream to write the object and use CipherInputStream and ObjectInputStream to read it, there is a better way.
The SealedObject class is a special container that encrypts serialized objects and lets you retrieve them again.
To store an object in a SealedObject container, you must first create a Cipher, just as you do for other encryption/decryption processes. Then, just pass the object you want to encrypt and the Cipher to the SealedObject constructor:
SealedObject sealed = new SealedObject(myObject, myCipher);
Because the SealedObject class is serializable, ...
Get Special Edition Using Java™ 2 Enterprise Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.