First of all, I think Url encoded value pasted above is corrupted. In url encoding, hexedecimal representation must lead after %
character. But there is part like this: %1E% %06
You can use this TextUtil class to encode/decode from/to byte array!
String xmlValue = <your xml captcha value>
byte[] decoded = TextUtil.urlDecode(xmlValue.getBytes("UTF-8"));
public final class TextUtil {
static final String HEX_DIGITS = "0123456789ABCDEF";
protected static String urlEncode(byte[] rs) {
StringBuffer result = new StringBuffer(rs.length * 2);
for (int i = 0; i < rs.length; i++) {
char c = (char) rs[i];
switch (c) {
case '_':
case '.':
case '*':
case '-':
case '/':
result.append(c);
break;
case ' ':
result.append('+');
break;
default:
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9')) {
result.append(c);
} else {
result.append('%');
result.append(HEX_DIGITS.charAt((c & 0xF0) >> 4));
result.append(HEX_DIGITS.charAt(c & 0x0F));
}
}
}
return result.toString();
}
protected static byte[] urlDecode(byte[] bytes) throws UnsupportedEncodingException,
IllegalArgumentException {
if (bytes == null) {
return null;
}
byte[] decodeBytes = new byte[bytes.length];
int decodedByteCount = 0;
try {
for (int count = 0; count < bytes.length; count++) {
switch (bytes[count]) {
case '+':
decodeBytes[decodedByteCount++] = (byte) ' ';
break;
case '%':
decodeBytes[decodedByteCount++] = (byte) ((HEX_DIGITS.indexOf(bytes[++count]) << 4) + (HEX_DIGITS
.indexOf(bytes[++count])));
break;
default:
decodeBytes[decodedByteCount++] = bytes[count];
}
}
} catch (IndexOutOfBoundsException ae) {
throw new IllegalArgumentException("Malformed encoding");
}
return decodeBytes;
}
}