設計此種編碼是為了使二進位制資料可以通過非純 8-bit 的傳輸層傳輸,例如電子郵件的內容就是通過base64轉碼後傳輸的。base64-encoded後, 資料要比原始資料多占用 33% 左右的空間。
利用base64加密檔案:
0102
0304
0506
0708
0910
1112
1314
1516
17//寫檔案路徑
$file_url
=
'upload/iampdf.pdf'
;
$file_encoded
=
'encoded/iampdf.pdf'
;
//獲取檔案資料
$data
=
file_get_contents
(
$file_url
);
//轉碼加密
$data_encode
=
base64_encode
(
$data
);
//儲存加密後的檔案
file_put_contents
(
$data_encode
,
$file_encoded
);
解密base64加密後的檔案:
0102
0304
0506
0708
0910
1112
1314
15$file_url
=
'upload/iampdf.pdf'
;
$file_encoded
=
'encoded/iampdf.pdf'
;
//讀取檔案資料
$data_encode
=
file_get_contents
(
$file_encoded
);
//解密
$data
=
base64_decode
(
$data
);
//儲存解密後的檔案
file_put_contents
(
$data
,
$file_url
);
其實上面的操作還算不上加密,只要懂解碼分分鐘可以獲取原檔案。所以,有興趣的可以再對轉碼後的檔案進行字串位移、轉換等操作,那樣就做到真正的加密了。
利用base64函式,對檔案進行轉碼加密
設計此種編碼是為了使二進位制資料可以通過非純 8 bit 的傳輸層傳輸,例如電子郵件的內容就是通過base64轉碼後傳輸的。base64 encoded後,資料要比原始資料多占用 33 左右的空間。利用base64加密檔案 寫檔案路徑 file url upload iampdf.pdf file ...
利用Base64對文字進行加密解密操作
有時候我們需要對資料進行加密解密,最常見的加密方法有md5加密 base64加密。而今天講的是base64加密解密方法,我們需要引用兩個檔案using system.collections.generic 和using system.security.cryptography 同時我們定義兩個變數 ...
利用openssl進行base64的編碼與解碼
openssl可以直接使用命令對檔案件進行base64的編碼與解碼,利用openssl提供的api同樣可以做到這一點。廢話不多說,直接上 了。需要注意的是通過base64編碼後的字元每64個位元組都會有乙個換行符的存在。static int base64 encode char str,int st...