Because it is no longer UTF-8 string data, dear. You encrypted it. DES generates unreadable binary data. If you force new String to interpret it according to UTF-8 encoding, of course it will be garbled. If it can be read directly, what's the point of encrypting it? Because most data encrypted based on mathematical algorithms generate binary blocks or stream data. Only after decryption can the original text be read. If you want the encrypted data to be stored as text or HTTP transmission, you can encode the data with BASE64. After encoding, it will be an ASCII string and will not be garbled (of course, humans still can't understand it).
This may be because you do not understand the difference between memory byte data stream and string. If you have used a text editor to display the data in hexadecimal, then you will not have this question. Why can String display a string? , that’s because the memory data conforms to certain encoding rules, such as UTF-8 encoding. But generally the data after des encryption is a complete memory data stream, which does not comply with the string encoding rules, so you force When you use string encoding rules to parse it, it will become "garbled code".
But if the purpose of encryption is not correct, then people can’t understand it?
Because it is no longer UTF-8 string data, dear. You encrypted it. DES generates unreadable binary data. If you force new String to interpret it according to UTF-8 encoding, of course it will be garbled. If it can be read directly, what's the point of encrypting it?
Because most data encrypted based on mathematical algorithms generate binary blocks or stream data. Only after decryption can the original text be read.
If you want the encrypted data to be stored as text or HTTP transmission, you can encode the data with BASE64. After encoding, it will be an ASCII string and will not be garbled (of course, humans still can't understand it).
After encryption, it is a byte array. Not all byte arrays can be converted into strings through new String()
This may be because you do not understand the difference between memory byte data stream and string.
But if the purpose of encryption is not correct, then people can’t understand it?If you have used a text editor to display the data in hexadecimal, then you will not have this question.
Why can String display a string? , that’s because the memory data conforms to certain encoding rules, such as UTF-8 encoding. But generally the data after des encryption is a complete memory data stream, which does not comply with the string encoding rules, so you force When you use string encoding rules to parse it, it will become "garbled code".
After encryption, it should be unreadable.
There is a similar article here https://segmentfault.com/q/10...
Why do you think it’s not gibberish?
After encryption, it is usually a byte array, which can be converted into a hexadecimal string.
After encryption, you can use Base64,