How to Base64 encode a Java object using org.apache.commons.codec.binary.base64?

后端 未结 2 1725
傲寒
傲寒 2021-02-13 02:52

I\'ve been trying to do an object serialization and Base64 encode the result. It works with Sun\'s lib:

Bean01 bean01 = new Bean01();
bean01.setDefaultValues();
         


        
2条回答
  •  佛祖请我去吃肉
    2021-02-13 03:20

    From commons-codec home page:

    Codec was formed as an attempt to focus development effort on one definitive implementation of the Base64 encoder. At the time of Codec's proposal, there were approximately 34 different Java classes that dealt with Base64 encoding spread over the Foundation's CVS repository. Developers in the Jakarta Tomcat project had implemented an original version of the Base64 codec which had been copied by the Commons HttpClient and Apache XML project's XML-RPC subproject. After almost one year, the two forked versions of Base64 had significantly diverged from one another. XML-RPC had applied numerous fixes and patches which were not applied to the Commons HttpClient Base64. Different subprojects had differing implementations at various levels of compliance with the RFC 2045.

    I think your problem is the "various level" of compliance.

    My advice: choose one base64 encoder/decoder and stick to it

提交回复
热议问题