1. 程式人生 > >Linux中使用base64編碼中文

Linux中使用base64編碼中文

上篇mail自動傳送中文標題郵件中提到需要用到base64編碼中文,本篇主要講使用base64的方式

1、Anne-Wei:~ $  base64

helloaGVsbG8=

直接輸入base64回車後,輸入需要編碼的內容後鍵盤輸入ctrl+D,即可得到hello的base64編碼

請看如下情況:

2、Anne-Wei:~ $  base64
       hello
aGVsbG8K
3、Anne-Wei:~ $  echo hello |base64
aGVsbG8K
4、Anne-Wei:~ $  echo -n  hello |base64
aGVsbG8=

1和4結果一致,2和3結果一致。hello正確的base64編碼應為1和4。2和3是hello+回車的base64編碼。

base64解碼:

Anne-Wei:~ $  echo hello |base64 |base64 -d

hello

Anne-Wei:~ $ base64 filename

Anne-Wei:~ $cat filename | base64