\Xcrypt

常用对称加密算法类 支持密钥:64/128/256 bit(字节长度8/16/32) 支持算法:DES/AES(根据密钥长度自动匹配使用:DES:64bit AES:128/256bit) 支持模式:CBC/ECB/OFB/CFB 密文编码:base64字符串/十六进制字符串/二进制字符串流 填充方式: PKCS5Padding(DES)

include "cls.xcrypt.php";

echo '

';
//////////////////////////////////////
$a = isset($_GET['a']) ? $_GET['a'] : '测试123';

//密钥 $key = '12345678123456781234567812345678'; //256 bit $key = '1234567812345678'; //128 bit $key = '12345678'; //64 bit

//设置模式和IV $m = new Xcrypt($key, 'cbc', 'auto');

//获取向量值 echo '向量:'; var_dump($m->getIV());

//加密 $b = $m->encrypt($a, 'base64'); //解密 $c = $m->decrypt($b, 'base64'); ///////////////////////////////////////// echo '

';

Summary

Methods
Properties
Constants
__construct()
getIV()
encrypt()
decrypt()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
_pkcs5Pad()
_pkcs5Unpad()
_hex2bin()
$mcrypt
$key
$mode
$iv
$blocksize
N/A

Properties

$mcrypt

$mcrypt

$key

$key

$mode

$mode

$iv

$iv

$blocksize

$blocksize

Methods

__construct()

__construct(mixed  $key, mixed  $mode = 'cbc', mixed  $iv = 'off') : mixed

构造函数

Parameters

mixed $key
mixed $mode
mixed $iv

Returns

mixed —

getIV()

getIV(mixed  $code = 'base64') : string

获取向量值

Parameters

mixed $code

Returns

string —

向量值

encrypt()

encrypt(mixed  $str, mixed  $code = 'base64') : string

加密

Parameters

mixed $str
mixed $code

Returns

string —

密文

decrypt()

decrypt(mixed  $str, mixed  $code = 'base64') : string

解密

Parameters

mixed $str
mixed $code

Returns

string —

明文

_pkcs5Pad()

_pkcs5Pad(mixed  $text) : mixed

Parameters

mixed $text

Returns

mixed —

_pkcs5Unpad()

_pkcs5Unpad(mixed  $text) : mixed

Parameters

mixed $text

Returns

mixed —

_hex2bin()

_hex2bin(mixed  $hex = false) : mixed

Parameters

mixed $hex

Returns

mixed —