Skip to Main Content

Java Security

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

com.misc.BASE64Encoder vs. org.apache.commons.codec.binary.Base64

843811Jan 19 2007 — edited Oct 14 2009
Since I don't want to use anything from the com.misc package, I wanted to move away frm using BASE64Encoder in my encryption method. I decided to use the Base64 object from the org.apache.commons.codec.binary package in the Apache Commons library.

Running the switch, however, my unit tests fail. Does anyone have any suggestions on what to use instead of Base64 and BASE64Encoder or tell me what I'm doing wrong?

Original Code:
MessageDigest digest = getLocalDigest();
byte[] digested = digest.digest(data);
enc = new BASE64Encoder().encode(digested);
New Code:
MessageDigest digest = getLocalDigest();
byte[] digested = digest.digest(data);
enc = new Base64().encode(digested).toString();
Unit Test:
stringResult1 = new Encryptor().encrypt(string);
stringResult2 = new Encryptor().encrypt(string);
assertEquals("Encryption of Identical String", stringResult1, stringResult2);
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 11 2009
Added on Jan 19 2007
4 comments
311 views