user1718720
user1718720

Reputation:

Java display invalid characters?

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.

Upvotes: 1

Views: 251

Answers (2)

Aurand
Aurand

Reputation: 5547

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

Upvotes: 2

Pragmateek
Pragmateek

Reputation: 13396

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.

Upvotes: 1

Related Questions