爲什麼需要Base64編碼&爲什麼需要二進制轉16進制

爲什麼需要Base64編碼

來源於知乎大佬的文章

Base64編碼跟Hex區別

計算機中任何數據都是 ASCII 碼存儲的, ascii 是 128-255 之間的不可見字符。
在網絡上進行數據交換,從 A 到 B, 往往要經過多個路由器,
不同設備之間對字符的處理方式有一些不同,不可見字符有可能被錯誤處理,是不利於傳輸的,
因此要先做一個 base64 編碼,變成可見字符,便於傳輸

英文解析

When you have some binary data that you want to ship across a network, 
you generally don't do it by just streaming the bits and bytes over the wire in a raw format. 
Why? because some media are made for streaming text. 
You never know -- some protocols may interpret your binary data as control characters (like a modem), 
or your binary data could be screwed up because the underlying protocol might think that you've entered a special character combination (like how FTP translates line endings). 
So to get around this, people encode the binary data into characters. Base64 is one of these types of encodings. 
Why 64? Because you can generally rely on the same 64 characters being present in many character sets, and you can be reasonably confident that your data's going to end up on the other side of the wire uncorrupted.

Base64 編碼後,解碼能得到原本數據

爲什麼需要二進制轉16進制

一切“字符”都必定用數字+編碼表表示

ASCII編碼表
GB2312編碼表
UNICODE讓全世界都說一種語言

原本數據二進制轉成16進制,再從16進制轉回原數據,是可以互轉的

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章