From a16ae1203ba63449ebea91422ab2fc51e8470094 Mon Sep 17 00:00:00 2001 From: mguessan Date: Sun, 2 Mar 2014 20:14:17 +0000 Subject: [PATCH] From coverity: use UTF-8 encoding in Hex conversion methods git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@2239 3d1905a2-6b24-0410-a738-b14d5a86fcbd --- src/java/davmail/util/StringUtil.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/java/davmail/util/StringUtil.java b/src/java/davmail/util/StringUtil.java index d09773fe..9beba9ea 100644 --- a/src/java/davmail/util/StringUtil.java +++ b/src/java/davmail/util/StringUtil.java @@ -22,6 +22,7 @@ import org.apache.commons.codec.DecoderException; import org.apache.commons.codec.binary.Base64; import org.apache.commons.codec.binary.Hex; +import java.io.UnsupportedEncodingException; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; @@ -296,10 +297,10 @@ public final class StringUtil { * @param value base64 value * @return hex value */ - public static String base64ToHex(String value) { + public static String base64ToHex(String value) throws UnsupportedEncodingException { String hexValue = null; if (value != null) { - hexValue = new String(Hex.encodeHex(Base64.decodeBase64(value.getBytes()))); + hexValue = new String(Hex.encodeHex(Base64.decodeBase64(value.getBytes("UTF-8")))); } return hexValue; } @@ -311,10 +312,10 @@ public final class StringUtil { * @return base64 value * @throws DecoderException on error */ - public static String hexToBase64(String value) throws DecoderException { + public static String hexToBase64(String value) throws DecoderException, UnsupportedEncodingException { String base64Value = null; if (value != null) { - base64Value = new String(Base64.encodeBase64(Hex.decodeHex(value.toCharArray()))); + base64Value = new String(Base64.encodeBase64(Hex.decodeHex(value.toCharArray())), "UTF-8"); } return base64Value; }