java - How to convert byte string to byte[] -


i stuck casting issue converting byte string byte array.

i.e have string "[b@1a758cb". base64 encrypted string of main string "gunjan". here decryption want convert encrypted byte string byte[].

but string.getbyte[] not working me. string.getbytes[] gives bytes of byte string.

how can ?? have iterate on each character in byte string , convert them byte[] ??

edited

i using apache coded 3.1 jar base64 conversion. here code getting encrypted text..

string in = "gunjan"; byte[] bytestr = in.getbytes(); byte[] base64encoded = base64.encodebase64(bytestr); 

here value of base64encoded [b@1a758cb can see console log in image..enter image description here

first of all, don't have problem here, since decoded string value (gunjan) equal original value (gunjan).

you're confused printed intermediate byte arrays. noted in comments, strings [@bxxxx result of calling tostring() on byte array. desn't display value of bytes, type of array ([@b) followed hashcode of array object. if want display byte values, use

system.out.println(arrays.tostring(bytearray)); 

you have potential bug though: you're using default encoding transform strings bytes , vice-versa. encoding might not able support every character in string. should use specific encoding supports every character on earth, utf8:

byte[] bytestr = string.getbytes("utf8"); ... string str = new string (bytestr, "utf8"); 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -