1

I have written a program the performs the standard AES S-Box encryption. my problem is that when I encrypt the message it is supposed to write the text to a JTextArea, but it just shows a bunch of little square boxes and when I try to save it to a text document it just makes a bunch of question marks in the text file. how can I make it display the encrypted text? or can I even have it automatically write it to a text document without it creating a bunch of question marks?

I think that I have to use utf-8 text encoding but I have no idea how to do that.

2 Answers 2

2

Your text is encrypted as binary data. While encrypted it is not in any character set and cannot be rendered as text. If you want a way to view it, you could Base64 encode the encrypted data.

See: http://en.wikipedia.org/wiki/Base64

Sign up to request clarification or add additional context in comments.

2 Comments

already have base64 method incorporated, thanks tho i didn't know :P i am relatively new to more advanced cryptography, ill just display the binary
@user1718720 you can display the binary encoding (0 and 1 characters) but I would rather display them in hexadecimal format. One way to do this is to use String.format("%02X", byteValue). Relatively slow, but who cares with Gigahertz processors nowadays. Understanding the difference of bytes, byte arrays and encoding and character-encoding is essential for cryptography.
1

The output of the algorithm will not be a valid text in the general case.

If you need to manipulate it as text you can encrypt it in base-64 which uses only valid ASCII characters.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.