java - 为什么des加密后输出乱码?
大家讲道理
大家讲道理 2017-04-18 10:09:45
0
8
1096
大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(8)
PHPzhong

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.
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?

It’s just gibberish

黄舟

After encryption, it should be unreadable.

伊谢尔伦

There is a similar article here https://segmentfault.com/q/10...

PHPzhong

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,

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template