Is there an easy way to encrypt a java object?

前端 未结 7 1394
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-06 18:14

I\'d like to store a serialized object to a file however I\'d like to make it encrypted. It doesn\'t need to be really strong encryption. I just want something easy (preferably

7条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-06 18:38

    Use SealedObject and Cipher class to Encrypt and decrypt the object.

    What is SealedObject?

    SealedObject encapsulate the original java object(it should implements Serializable). It use the cryptographic algorithm to seals the serialized content of the object.

    What is Cipher?

    This is a java class, use cryptographic algorithm for encryption and decryption.

    Sample code

    below is the sample code.

    EncriptThisClass so = new EncriptThisClass();
    SealedObject encryptedObject =encryptObject(so);
    EncriptThisClass etcObject=decryptObject(encryptedObject);
    

    For complete code please visit the below link. http://javaant.com/object-encryption-decryption-in-java/#.VvkA6RJ96Hs

提交回复
热议问题