2011-07-07 34 views
0

我需要使用base 64來加密一些數據。 但是,雖然每個人都可以解碼它,但編碼它有意義嗎?base64的自定義映射表

,所以我需要使用定製馬平表編碼insted的的 「ABCD ...... 789 + /」

我發現了一個函數在php.net - http://www.php.net/manual/en/function.base64-encode.php#78765

它可以做我想要的 但我不知道如何解碼加密的數據。

你能幫我嗎

+3

base64編碼的想法是不加密數據,以防止它被讀取。它用於將8位數據轉換爲7位數據進行傳輸。換句話說,它用於將二進制數據轉換爲文本數據,以便可以通過無法處理二進制數據的機制發送/接收數據。例如,您可以選擇base64編碼的圖像數據在XML內發送。如果你想要只有你可以解密的加密,那麼base64不是正確的選擇。 –

+2

Base64是** NOT **加密。在加密領域,這相當於用溼紙巾包裝東西。 base64是一種通過可能破壞二進制數據的系統安全傳輸數據的機制。 –

+1

首先加密,然後編碼。 – hakre

回答

2

base64加密確實不是爲了安全。你想使用mcrypt或類似的。 base64專門用於以安全的方式傳輸數據,並且可以被多個感興趣的方所理解。

但是,這裏是你如何去解開那海報的方法:

如果你看看他的意見,他切換到「S」和9(實際上,他的陣列有兩個「S」,但我認爲第二個是一個錯字)。所以這應該工作:

// there is a more efficient way of doing this, but this was easy to demonstrate. 
// you'll need to use temp stand-ins 
$res = str_replace(array(9, 's'), array('{', '}'), $input); 
$res = str_replace(array('{', '}'), array('s', 9), $res); 
$base64_raw = ''; 

for($i = 0; $i < strlen($res); $i++) 
{ 
    $tmp = $res[ $i ]; 
    // if it is upper case, then append the lower-case version. 
    if($tmp == strtoupper($tmp)) $base64_raw .= strtolower($tmp); 
    // else append the upper-case version. 
    else $base64_raw .= strtoupper($tmp); 
} 

echo base64_decode($base64_raw);