日期:2014-05-17 浏览次数:20922 次
<?php
require_once ("../basic/db_site.php");
class DES_Class
{
const ConstantKey = 'MMM';
const ConstantIV = 'UUU';
private $key = "";
private $iv = "";
function __construct ()
{
$this->key = $this->stringArrKey(base64_encode(self::ConstantKey));
$this->iv = $this->stringArrIv(self::ConstantIV); //$this->stringArrIv($iv);
}
private function stringArrKey($inputStr)
{
$stringArray[]=array();
$inputStr=ltrim($inputStr);
$inputStr=rtrim($inputStr);
$stringArray=str_split($inputStr);
$strLength=strlen($inputStr);
$strOutput[]=array();
if ($strLength<8)
{
for ($i=0;$i<$strLength;$i++)
{
$strOutput[$i]=$stringArray[$i];
}
for ($i=$strLength;$i<8;$i++)
{
$strOutput[$i]='0';
}
}
else if ($strLength>8)
{
for ($i=0;$i<8;$i++)
{
$strOutput[$i]=$stringArray[$i];
}
}
$strOutputFinal=implode("",$strOutput);
return $strOutputFinal;
}
public function CreateLic($message)
{
$messageArr[] = array();
$messageReplace[] = array();
$messageArr=str_split($message);
for ($i=0;$i<5;$i++)
{
$messageReplace[$i] = $messageArr[5+$i];
}
for ($i=0;$i<5;$i++)
{
$messageReplace[5+$i] = $messageArr[$i];
}
$messageReplace[10] = $messageArr[10];
for ($i=0;$i<5;$i++)
{
$messageReplace[11+$i] = $messageArr[16+$i];
}
for ($i=0;$i<5;$i++)
{
$messageReplace[16+$i] = $messageArr[11+$i];
}
$message=implode("",$messageReplace);
$td = mcrypt_module_open(MCRYPT_3DES, '', MCRYPT_MODE_CBC, '');
$iv = base64_decode($this->iv);
$message = $this->PaddingPKCS7($message);
$key = base64_decode($this->key);
mcrypt_generic_init($td, $key, $iv);
$result = base64_encode(mcrypt_generic($td, $message));
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
return $result;
}
/***decode part-------public function*/
public function GetMessage ($license)
{
$td = mcrypt_module_open(MCRYPT_3DES, '', MCRYPT_MODE_CBC, '');
$iv = base64_decode($this->iv);
$key = base64_decode($this->key);
mcrypt_generic_init($td, $key, $iv);
$resul