PHP string crypt() 函數
crypt() 是預定義的 PHP 字符串函數。愛掏網 - it200.com它用于使用 DES、Blowfish 或 MD5 算法返回一個哈希字符串。愛掏網 - it200.com
以下是 crypt() 函數的一些常量:
- [CRYPT_STD_DES]
- [CRYPT_EXT_DES]
- [CRYPT_MD5]
- [CRYPT_BLOWFISH]
- [CRYPT_SHA_256]
- [CRYPT_SHA_512] 等。愛掏網 - it200.com
string crypt ( string str [, stringsalt ] );
參數 | 描述 | 必填/可選 |
---|---|---|
str | 指定要進行哈希處理的字符串 | 必填 |
salt | 指定一個鹽字符串 | 可選 |
注意:此crypt()函數適用于不同的操作系統。愛掏網 - it200.com
示例1
<?php
// 2 character salt
if (CRYPT_STD_DES == 1){
echo "Standard DES: ".crypt('javatpoint','jt')."\n<br>";
}
else{
echo "Standard DES not supported.\n<br>";
}
?>
輸出:
Standard DES: jtigeEQ4GnSRg \
示例2
<?php
// 4 character salt
if (CRYPT_EXT_DES == 1){
echo "Extended DES: ".crypt('javatpoint','_S4..java')."\n<br>";
}
else{
echo "Extended DES not supported.\n<br>";
}
?>
輸出:
Extended DES: _S4..javac7kJCJPxtp6
示例3
<?php
// 4 character salt
if (CRYPT_MD5 == 1){
echo "MD5: ".crypt('javatpoint','1javatpoint$')."\n<br>";
}
else{
echo "MD5 not supported.\n<br>";
}
?>
輸出:
MD5: 1javatpoi$/QyBQ/V7dJjcGaOq83EhL0
注意:使用16個字符以5開頭的鹽,并且默認的迭代輪數是5000。愛掏網 - it200.com
示例4
<?php
if (CRYPT_BLOWFISH == 1){
echo "Blowfish: ".crypt('javatpoint','2a09anexamplestringforsalt')."\n<br>";
}
else{
echo "Blowfish DES not supported.\n<br>";
}
?>
輸出:
Blowfish: 2a09$anexamplestringforsale8idRk7z/D1GAsmHMUTi1L/e7Cjcngiy
示例5
<?php
// 16 character salt starting with 5. The default number of rounds is 5000.
if (CRYPT_SHA256 == 1) {
echo "SHA-256: ".crypt('javatpoint','5rounds=5000anexamplestringforsalt')."\n<br>"; }
else{
echo "SHA-256 not supported.\n<br>";
}
?>
輸出:
SHA-256: 5rounds=5000anexamplestringfcdf4KmhoNRhj0riAq6kpiYdPHGWOBEnPxtPxje3Fjm2
示例6
// 16 character salt starting with 6. The default number of rounds is 5000.
if (CRYPT_SHA512 == 1)
{
echo "SHA-512: ".crypt('something','6rounds=5000anexamplestringforsalt');
}
else
{
echo "SHA-512 not supported.";
}
輸出:
SHA-512: 6rounds=5000anexamplestringfOo0skOAdUFXkQxJpwzO05wgRHG0dhuaPBaOU/oNbGpCEKlf/7oVM5wn6AN0w2vwUgA0O24oLzGQpp1XKI6LLQ0
示例7
<?php
// 16 character salt starting with 6. The default number of rounds is 5000.
if (CRYPT_SHA512 == 1) {
echo "SHA-512: ".crypt('something','6rounds=5000anexamplestringforsalt');
}
else{
echo "SHA-512 not supported.";
}
?>
輸出:
SHA-512: 6rounds=5000anexamplestringfOo0skOAdUFXkQxJpwzO05wgRHG0dhuaPBaOU/oNbGpCEKlf/7oVM5wn6AN0w2vwUgA0O24oLzGQpp1XKI6LLQ0
聲明:所有內容來自互聯網搜索結果,不保證100%準確性,僅供參考。如若本站內容侵犯了原著者的合法權益,可聯系我們進行處理。