I use encrypt(byte) code for input String
and then save encrypt(String) in DB.
I get String
encrypt from DB to decrypt it, but I need to cast String
to byte
without changing because decrypt get just byte.
I used s.getBytes();
but it changed it,
I need some code to cast string to byte without changing the String. Thank you so much.
getBytes()
doesn't change the string, it encodes string into a sequence of bytes using the platform's default charset.
In order to print the array of bytes as a String
value,
String s = new String(bytes);
Edit:
it seems as you want to print the string as bytes, for which you can use
Arrays.toString(bytes)
See this code,
String yourString = "This is an example text";
byte[] bytes = yourString.getBytes();
String decryptedString = new String(bytes);
System.out.println("Original String from bytes: " + decryptedString);
System.out.println("String represented as bytes : " + Arrays.toString(bytes));
Output,
Original String from bytes: This is an example text
String represented as bytes : [84, 104, 105, 115, 32, 105, 115, 32, 97, 110, 32, 101, 120, 97, 109, 112, 108, 101, 32, 116, 101, 120, 116]
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments