Is there an easy way to encrypt a java object?

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

    Cant you just use any encryption library at all? Your basic code would be

    Object o=...;
    String s= new String();
    ObjectOutputStream out = new ObjectOutputStream(StringStream(s));
    out.writeObject(o);
    

    And then you just pass s into any encryption system you want.

    Edit: I forgot that StringStream is a C++ thing, not a Java one. But you can basically do the same thing, take a look here.

提交回复
热议问题