|
|
|
รบกวนค่ะ มีcode การเข้ารหัสด้วย sha1 แต่จะเพิ่มค่า salt ด้วยจะต้องทำอย่างไรคะ |
|
|
|
|
|
|
|
code ประมาณนี้ค่ะ
Code (PHP)
<?
function encode($string,$key) {
$key = sha1($key);
$strLen = strlen($string);
$keyLen = strlen($key);
for ($i = 0; $i < $strLen; $i++) {
$ordStr = ord(substr($string,$i,1));
if ($j == $keyLen) { $j = 0; }
$ordKey = ord(substr($key,$j,1));
$j++;
$hash .= strrev(base_convert(dechex($ordStr + $ordKey),16,36));
}
return $hash;
}
function decode($string,$key) {
$key = sha1($key);
$strLen = strlen($string);
$keyLen = strlen($key);
for ($i = 0; $i < $strLen; $i+=2) {
$ordStr = hexdec(base_convert(strrev(substr($string,$i,2)),36,16));
if ($j == $keyLen) { $j = 0; }
$ordKey = ord(substr($key,$j,1));
$j++;
$hash .= chr($ordStr - $ordKey);
}
return $hash;
}
echo encode("Please Encode Me!","This is a key");
?>
Tag : PHP, MySQL
|
|
|
|
|
|
Date :
2014-09-27 19:02:34 |
By :
KwangKie |
View :
2014 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
salt ก็คือ key ไงครับผม
เอาโค้ดทดสอบ แบบนี้ก็ได้
$a = encode("deawx","$#*@&$(%&#&");
$b = decode($a,"$#*@&$(%&#&");
echo "Endcode ".$a."<br>";
echo "Decode ".$b."<br>";
|
|
|
|
|
Date :
2014-09-28 09:54:51 |
By :
deawx |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|