java - What's the difference between new String(byte[]) and DatatypeConverter.printBase64Binary(byte[])? -


i need pass base64 encoded data xml string value. noticed code below prints different string representation. 1 correct , why?

    string example = "hello universe!";     byte[] base64data = base64.encodebase64(example.getbytes());     system.out.println(new string(base64data));     system.out.println(datatypeconverter.printbase64binary(base64data));      system.out.println(new string(base64.decodebase64(base64data), "utf-8")); 

and result:

sgvsbg8gdw5pdmvyc2uh u0dwc2jhogdkvzvwzg1wewmyvwg= hello universe! 

u0dwc2jhogdkvzvwzg1wewmyvwg= decoded sgvsbg8gdw5pdmvyc2uh hello universe! encoded. did encoding twice.

there no difference. using api wrong way. don't encode encoded data again.


Comments

Popular posts from this blog

user interface - Python attempting to create a simple gui, getting "AttributeError: 'MainMenu' object has no attribute 'intro_screen'" -

jquery - Common JavaScript snippet to share files on Google Drive, Dropbox, Box.net or SkyDrive -

Android Gson.fromJson error -