how do I print the contents of an array of bytes as bytes?

mahdi

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.

Sufiyan Ghori

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

How do I manually assign bytes to a long in Kotlin?

From Java

How do I convert a Vector of bytes (u8) to a string

From Dev

How do I read exactly 4 bytes from an InputStream?

From Dev

How do I count which function requests what number of bytes?

From Dev

How do I compare if 2 images are the same using Hash bytes?

From Dev

Print out 26 bytes from an byte array

From Dev

How can I print 4 bytes as an integer

From Dev

How do I convert a string into a vector of bytes in rust?

From Dev

How do I decide how many bytes to read from an inputstream?

From Dev

How do I convert 4 bytes of a ByteString to an Int?

From Dev

How do I make Python 3.4 c_char_array read strings as two bytes?

From Dev

How do I convert a list of integers into bytes?

From Dev

Stream.CopyTo - How do I get the sent Bytes?

From Dev

In Perl, how can I convert an array of bytes to a Unicode string?

From Dev

How do I use null bytes in Bash?

From Dev

How do I get a bytes::bytes::Bytes from a std::string::String?

From Dev

How do I convert lists and dictionaries into bytes?

From Dev

How can I save a numpy array as bytes using a custom codec?

From Dev

How do I use null bytes in Bash?

From Dev

How to to print the size of a filesystem in bytes?

From Dev

How can I print 4 bytes as an integer

From Dev

How do I declare an array of bytes in Java?

From Dev

How to read an array of bytes from a file using datainput stream, and print the array of bytes in java

From Dev

How do I convert a list of integers into bytes?

From Dev

NASM assembly, How to print the first 4 bytes of a string array

From Dev

Python: How can I print bytes?

From Dev

returning a pointer that points to char array. How do i print out the entire contents of the array?

From Dev

How do I get a number from bytes?

From Dev

How to print uint8_t bytes array?

Related Related

  1. 1

    How do I manually assign bytes to a long in Kotlin?

  2. 2

    How do I convert a Vector of bytes (u8) to a string

  3. 3

    How do I read exactly 4 bytes from an InputStream?

  4. 4

    How do I count which function requests what number of bytes?

  5. 5

    How do I compare if 2 images are the same using Hash bytes?

  6. 6

    Print out 26 bytes from an byte array

  7. 7

    How can I print 4 bytes as an integer

  8. 8

    How do I convert a string into a vector of bytes in rust?

  9. 9

    How do I decide how many bytes to read from an inputstream?

  10. 10

    How do I convert 4 bytes of a ByteString to an Int?

  11. 11

    How do I make Python 3.4 c_char_array read strings as two bytes?

  12. 12

    How do I convert a list of integers into bytes?

  13. 13

    Stream.CopyTo - How do I get the sent Bytes?

  14. 14

    In Perl, how can I convert an array of bytes to a Unicode string?

  15. 15

    How do I use null bytes in Bash?

  16. 16

    How do I get a bytes::bytes::Bytes from a std::string::String?

  17. 17

    How do I convert lists and dictionaries into bytes?

  18. 18

    How can I save a numpy array as bytes using a custom codec?

  19. 19

    How do I use null bytes in Bash?

  20. 20

    How to to print the size of a filesystem in bytes?

  21. 21

    How can I print 4 bytes as an integer

  22. 22

    How do I declare an array of bytes in Java?

  23. 23

    How to read an array of bytes from a file using datainput stream, and print the array of bytes in java

  24. 24

    How do I convert a list of integers into bytes?

  25. 25

    NASM assembly, How to print the first 4 bytes of a string array

  26. 26

    Python: How can I print bytes?

  27. 27

    returning a pointer that points to char array. How do i print out the entire contents of the array?

  28. 28

    How do I get a number from bytes?

  29. 29

    How to print uint8_t bytes array?

HotTag

Archive