Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
368 views
in Technique[技术] by (71.8m points)

java - Why does my encrypted string looks like consisting of only question marks?

I'm encrypting a string in Java, and when I'm printing the encrypted data, I see only question marks.

As an example:

  • Plain text: jjkkjlkljkj

  • Encrypted text: ???????????

  • After decrypting this text again, I'm getting jjkkjlkljkj again.

So it looks like the encryption worked right. But why can I see only question marks?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Yes, it's because you can't print the strings that are resulting from the encryption.

Note that saving the encrypted result in a string will possibly result in loss of the data, so don't do that. Take it as a byte array, and convert it to a displayable format, like Base64 or just simple Hex.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...