des加密是對稱加密中在網際網路應用的比較多的一種加密方式,php 通過mcrypt擴充套件庫來支援des加密,要在php中使用des加密,需要先安裝mcrypt擴充套件庫
下面是加密解密的例項
[php]view plain
copy
$iv_size
= mcrypt_get_iv_size(mcrypt_rijndael_256, mcrypt_mode_ecb);
$iv= mcrypt_create_iv(
$iv_size
, mcrypt_rand);
$key
= "this is a very secret key"
;//金鑰
$text
= "meet me at 11 o'clock behind the monument."
;//需要加密的內容
echo
($text
) .
"\n"
; $crypttext
=base64_encode
(mcrypt_encrypt(mcrypt_rijndael_256,
$key
, $text
, mcrypt_mode_ecb,
$iv));
echo
$crypttext
. "\n"
;//加密後的內容
echo
mcrypt_decrypt(mcrypt_rijndael_256,
$key
,base64_decode
($crypttext
),mcrypt_mode_ecb,
$iv);
//解密後的內容
在aes加密演算法中通常會用到mcrypt_rijndael_128、mcrypt_rijndael_192、mcrypt_rijndael_256三種,後面的128、192、256代表的是秘鑰(也就是加密的key)是多少bit的,比如使用的是mcrypt_rijndael_128,那麼用這個演算法加密時秘鑰長度就是128bit的,比如 $key = 'fjjda0&9^$$#+*%$fada',是20個字元,那在實際加密的時候只用到前16個字元加密(16*8=128),不足128bit的php中會用'\0'來補齊。
PHP DES加密解密
自定義密碼加密解密函式,源自,記錄儲存一下。1 3 des加密解密4 5class mcrypt89 function getskey msg 13 開啟加密演算法和模式 14 td mcrypt module open des ecb 15 建立初始向量,並且檢測金鑰長度。windows 平台請使...
MySQL加密和解密例項詳解
mysql加密和解密例項詳解 資料加密 解密在安全領域非常重要。對程式設計師而言,在資料庫中以密文方式儲存使用者密碼對入侵者剽竊使用者隱私意義重大。有多種前端加密演算法可用於資料加密 解密,下面我向您推薦一種簡單的資料庫級別的資料加密 解密解決方案。以mysql資料庫為例,它內建了相應的加密函式 a...
加密解密實驗
定義加密文字 str1 你好啊 str2 我很好 str3 吃了嗎 str4 馬上吃 利用函式置換密碼 table1 str.maketrans str1,str2 table2 str.maketrans str2,str3 table3 str.maketrans str3,str4 table...