Question

For my encryption software, I have to decrypt the contents of a JTextArea when the decryption button is pressed.

How do I get a byte[] containing the contents of my text area?

Was it helpful?

Solution

From your limited description, it sounds like you want to retrieve text from a JTextArea in the form of bytes.

This is straight-forward enough:

byte[] data = yourTextArea.getText().getBytes("charset-name");

Replace "charset-name" with your preferred character set.

OTHER TIPS

If your encrypted data starts with "[B@" it means that you are using ".toString()" in your code and it isnt the real encrypted data. To prove it, print the length too and you will see that its a lot longer. If you want the encrypted data do a for loop like this:

byte[] encryptedText=encrypt("Hello");

for(int i=0;i<encryptedText.length();i++) {
String s=String.valueOf(encryptedText[i]);
System.out.print(s);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top