Is there an easy way to encrypt a java object?

前端 未结 7 1385
爱一瞬间的悲伤
爱一瞬间的悲伤 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:46

    You should look into Jasypt. It has a bunch of utility functions to make this easy.

    ...
    BasicTextEncryptor textEncryptor = new BasicTextEncryptor();
    textEncryptor.setPassword(myEncryptionPassword);
    ...
    String myEncryptedText = textEncryptor.encrypt(myText);
    ...
    String plainText = textEncryptor.decrypt(myEncryptedText);
    ...
    

提交回复
热议问题