background image

注意:解密后的数据可能比实际上的更长,可能会有后续的

\0,需去掉 

 
-------------------------------------------------------------------------------- 
bool mcrypt_module_close ( resource 

$td

 ) 

关闭指定的加密模块资源句柄

 

返回值

 

成功时返回

 TRUE, 或者在失败时返回 FALSE. 

 
-------------------------------------------------------------------------------- 
贴上代码:

 

复制代码

 代码如下:

 
<?php 

class

 authCode { 

public

 

$ttl

;

//到期时间 时间格式:20120101(年月日) 

public

 

$key_1

;

//密钥 1 

public

 

$key_2

;

//密钥 2 

public

 

$td

public

 

$ks

;

//密钥的长度 

public

 

$iv

;

//初始向量 

public

 

$salt

;

//盐值(某个特定的字符串) 

public

 

$encode

;

//加密后的信息 

public

 

$return_array

 = 

array

(); 

// 返回带有 MAC 地址的字串数组 

public

 

$mac_addr

;

//mac 地址 

public

 

$filepath

;

//保存密文的文件路径 

public

 

function

 __construct(){ 

//获取物理地址 

$this

->mac_addr=

$this

->getmac(PHP_OS); 

$this

->filepath="./licence.txt"; 

$this

->ttl="20120619";

//到期时间 

$this

->salt="~!@#$";

//盐值,用以提高密文的安全性 

// echo "<pre>".print_r(mcrypt_list_algorithms ())."</pre>"; 
// echo "<pre>".print_r(mcrypt_list_modes())."</pre>"; 

/** 
* 对明文信息进行加密 
* @param $key 密钥 
*/

 

public

 

function

 encode(

$key

) { 

$this

->td = mcrypt_module_open(MCRYPT_DES,'','ecb',''); 

//使用 MCRYPT_DES 算法,ecb 模

 

$size

=mcrypt_enc_get_iv_size(

$this

->td);

//设置初始向量的大小 

$this

->iv = mcrypt_create_iv(

$size

, MCRYPT_RAND);

//创建初始向量 

$this

->ks = mcrypt_enc_get_key_size(

$this

->td);

//返回所支持的最大的密钥长度(以字节计