Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

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!

Unexpected whitespace when encoding text

843834May 18 2009 — edited May 20 2009
Hello,

Anyone an idea why in mail-1.4.2.jar when using encoding a whitespace is added? In mail-1.4.jar this was not the case. This can for example cause problems when you use the encoding to create encrypted passwords for storage in databases. I already added a bug report (1519938) which is in review. I added some info from the bug report below.

With regards.
Paul


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Sample code is added to this bug report. Simply run using the different mail.jar versions.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The output of the example code should be:

Crypt this: 'wDgHDzqoH2USqnK72P+xZk4k+tg='

ACTUAL -
The output of the example code with mail-1.4.2.jar was:

Crypt this: 'wDgHDzqoH2USqnK72P+xZk4k+tg=
'

As can be seen a trailing enter is added before the closing single quote.

---------- BEGIN SOURCE ----------
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import javax.mail.MessagingException;
import javax.mail.internet.MimeUtility;

public class TestCryptSomeText {

private static final String SHA1 = "SHA1";

private static String getMd5Base64(String cryptThis)
throws NoSuchAlgorithmException, MessagingException, IOException {
MessageDigest md = MessageDigest.getInstance(SHA1);
byte[] b = md.digest(cryptThis.getBytes());
ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
OutputStream out = MimeUtility.encode(byteOut, "base64");
out.write(b);
out.close();
return byteOut.toString();
}

public static void main(String[] args) throws
IOException, NoSuchAlgorithmException, MessagingException {

String cryptThis = "1a2b3c5b6h";
String result = getMd5Base64(cryptThis);
System.out.println("Crypt this: '" + result + "'");
}

}
---------- END SOURCE ----------
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 17 2009
Added on May 18 2009
3 comments
123 views