문제

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);
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top