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?
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.
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);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.