How to encrypt serialized object using DES (CBC mode) in Java?

I read this article about serialization.

The first time I saw the encryption of a serialized object. I am trying to encrypt some serializable object and then save them to a file. But the example article uses ECB mode, which, as you know, reveals information about encrypted plaintext. I was wondering, how can I encrypt a serialized object using CBC instead of ECB mode?

To use CBC, you need an initial vector. This vector must be saved using a serialized object, but if the vector is encrypted, we cannot find the vector to decrypt the object.

In addition, is it possible to say that the original vector will be saved as plain text in the file where the serialiazable object is stored. But then the file will not be destroyed?

An example of using CBC mode will be very useful.

+4
source share
1 answer

There is a decent question and answer about using 3DES here . IV is the password / key digest. The above solution can be supplemented by the appropriate serialization mechanics to ByteArrayOutputStream or directly to / from a FileOutputStream .

(Not an expert in any way, but indicating that on SO already ...)

0
source

Source: https://habr.com/ru/post/1339436/


All Articles