Reputation: 1321
I am using JNDI to connect to a LDAP server. A few attributes on the server are stored as BASE64 string.
However, when I query the server and get results back. These attributes are already decoded but not properly. For example, "[email protected]" may be decoded as "abcû[email protected]".
Any idea on how can I fix this?
Added:
The original BASE64 string is:
Q049XCtHcm91cCBBUFNHLU9uLWJvYXJkaW5n4oCTTllDLE9VPU5ZQyxPV
20=
Upvotes: 0
Views: 1524
Reputation: 116938
This looks to be a problem between UTF16, which is Java's native character format, and UTF8. The entity that is encoding the string must be UTF8.
To decode a string from UTF8 use:
// to decode a string
String decoded = new String(Base64.decodeBase64(encoded.getBytes()), "UTF8");
That gives me the right output. If you need to convert a UTF8 string to be UTF16 you'd do:
new String(utf8String.getBytes(), "UTF8");
Upvotes: 2