本文整理汇总了PHP中mcrypt_module_close函数的典型用法代码示例。如果您正苦于以下问题:PHP mcrypt_module_close函数的具体用法?PHP mcrypt_module_close怎么用?PHP mcrypt_module_close使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了mcrypt_module_close函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: computeSign
public function computeSign($sharedSecret)
{
if (!$this->isValid) {
throw new Exception(__METHOD__ . ": Message was not validated.");
}
try {
// ak mame zadany shared secret v hexa tvare tak ho prevedieme na 32 bytovy string
if (strlen($sharedSecret) == 64) {
$sharedSecret = pack('H*', $sharedSecret);
}
$base = $this->GetSignatureBase();
$bytesHash = sha1($base, TRUE);
// vezmeme prvych 16 bytov
$bytesHash = substr($bytesHash, 0, 16);
$aes = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_ECB, '');
$iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($aes), MCRYPT_RAND);
mcrypt_generic_init($aes, $sharedSecret, $iv);
$bytesSign = mcrypt_generic($aes, $bytesHash);
mcrypt_generic_deinit($aes);
mcrypt_module_close($aes);
$sign = strtoupper(bin2hex($bytesSign));
} catch (Exception $e) {
return FALSE;
}
return $sign;
}
示例2: decrypt
public function decrypt($encrypted, $corpid)
{
try {
$ciphertext_dec = base64_decode($encrypted);
$module = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, '');
$iv = substr($this->key, 0, 16);
mcrypt_generic_init($module, $this->key, $iv);
$decrypted = mdecrypt_generic($module, $ciphertext_dec);
mcrypt_generic_deinit($module);
mcrypt_module_close($module);
} catch (Exception $e) {
return array(ErrorCode::$DecryptAESError, null);
}
try {
//去除补位字符
$pkc_encoder = new PKCS7Encoder();
$result = $pkc_encoder->decode($decrypted);
//去除16位随机字符串,网络字节序和AppId
if (strlen($result) < 16) {
return "";
}
$content = substr($result, 16, strlen($result));
$len_list = unpack("N", substr($content, 0, 4));
$xml_len = $len_list[1];
$xml_content = substr($content, 4, $xml_len);
$from_corpid = substr($content, $xml_len + 4);
} catch (Exception $e) {
print $e;
return array(ErrorCode::$DecryptAESError, null);
}
if ($from_corpid != $corpid) {
return array(ErrorCode::$ValidateSuiteKeyError, null);
}
return array(0, $xml_content);
}
示例3: enkripsi_plain2
function enkripsi_plain2($algoritma, $mode, $secretkey, $fileplain)
{
/* Membuka Modul untuk memilih Algoritma & Mode Operasi */
$td = mcrypt_module_open($algoritma, '', $mode, '');
/* Inisialisasi IV dan Menentukan panjang kunci yang digunakan*/
$iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
$ks = mcrypt_enc_get_key_size($td);
/* Menghasilkan Kunci */
$key = $secretkey;
//echo "kuncinya : ". $key. "<br>";
/* Inisialisasi */
mcrypt_generic_init($td, $key, $iv);
/* Enkripsi Data, dimana hasil enkripsi harus di encode dengan base64.\
Hal ini dikarenakan web browser tidak dapat membaca karakter-karakter\
ASCII dalam bentuk simbol-simbol */
$buffer = $fileplain;
$encrypted = mcrypt_generic($td, $buffer);
$encrypted1 = base64_encode($iv) . ";" . base64_encode($encrypted);
$encrypted2 = base64_encode($encrypted1);
$filecipher = $encrypted2;
/* Menghentikan proses enkripsi dan menutup modul */
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
return $filecipher;
}
示例4: __destruct
public function __destruct()
{
mcrypt_module_close($this->cipher);
unset($this->cipher);
unset($this->iv);
unset($this->cipher_key);
}
示例5: decrypt
public static function decrypt($string, $key = null, $salt = null, $iv = null)
{
$config = ConfigManager::getConfig('Crypto', 'AES256')->AuxConfig;
if ($key === null) {
$key = $config->key;
}
if ($salt === null) {
$salt = $config->salt;
}
if ($iv === null) {
$iv = $config->iv;
}
$td = mcrypt_module_open('rijndael-128', '', MCRYPT_MODE_CBC, '');
$ks = mcrypt_enc_get_key_size($td);
$bs = mcrypt_enc_get_block_size($td);
$iv = substr(hash("sha256", $iv), 0, $bs);
// Create key
$key = Crypto::pbkdf2("sha512", $key, $salt, $config->pbkdfRounds, $ks);
// Initialize encryption module for decryption
mcrypt_generic_init($td, $key, $iv);
$decryptedString = "";
// Decrypt encrypted string
try {
if (ctype_xdigit($string)) {
$decryptedString = trim(mdecrypt_generic($td, pack("H*", $string)));
}
} catch (ErrorException $e) {
}
// Terminate decryption handle and close module
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
// Show string
return $decryptedString;
}
示例6: decrypt
public function decrypt($encrypted, $is_id = false)
{
static $_map = array();
if ($is_id) {
$len = strlen($encrypted);
$tmp = '';
for ($i = 0; $i < $len; $i = $i + 2) {
$tmp = $tmp . chr(hexdec($encrypted[$i] . $encrypted[$i + 1]));
}
$encrypted = $tmp;
} else {
$encrypted = base64_decode($encrypted);
}
$hashkey = md5($encrypted . $this->key);
if (isset($_map[$hashkey])) {
return $_map[$hashkey];
}
$key = str_pad($this->key, 24, '0');
$td = mcrypt_module_open(MCRYPT_3DES, '', 'ecb', '');
$iv = @mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
$ks = mcrypt_enc_get_key_size($td);
@mcrypt_generic_init($td, $key, $iv);
$decrypted = mdecrypt_generic($td, $encrypted);
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
$y = $this->pkcs5_unpad($decrypted);
if ($is_id) {
$y = base_convert($y, 36, 10);
}
$_map[$hashkey] = $y;
return $y;
}
示例7: ssl_encode
function ssl_encode($data, $key = '')
{
// Use the Encrypt.php function get_key to encode the data.
$key = $this->get_key($key);
// Set a random salt
$salt = substr(md5(mt_rand(), true), 8);
$block = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
$pad = $block - strlen($data) % $block;
$data = $data . str_repeat(chr($pad), $pad);
// Setup encryption parameters
$td = mcrypt_module_open(MCRYPT_RIJNDAEL_128, "", MCRYPT_MODE_CBC, "");
$key_len = mcrypt_enc_get_key_size($td);
$iv_len = mcrypt_enc_get_iv_size($td);
$total_len = $key_len + $iv_len;
$salted = '';
$dx = '';
// Salt the key and iv
while (strlen($salted) < $total_len) {
$dx = md5($dx . $key . $salt, true);
$salted .= $dx;
}
$key = substr($salted, 0, $key_len);
$iv = substr($salted, $key_len, $iv_len);
mcrypt_generic_init($td, $key, $iv);
$encrypted_data = mcrypt_generic($td, $data);
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
return chunk_split(base64_encode('Salted__' . $salt . $encrypted_data), 32, "\n");
}
示例8: decrypt
public function decrypt($encrypted, $appid)
{
try {
$ciphertext_dec = base64_decode($encrypted);
$module = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, '');
$iv = substr($this->key, 0, 16);
mcrypt_generic_init($module, $this->key, $iv);
$decrypted = mdecrypt_generic($module, $ciphertext_dec);
mcrypt_generic_deinit($module);
mcrypt_module_close($module);
} catch (Exception $e) {
return array(ErrorCode::$DecryptAESError, NULL);
}
try {
$pkc_encoder = new PKCS7Encoder();
$result = $pkc_encoder->decode($decrypted);
if (strlen($result) < 16) {
return '';
}
$content = substr($result, 16, strlen($result));
$len_list = unpack('N', substr($content, 0, 4));
$xml_len = $len_list[1];
$xml_content = substr($content, 4, $xml_len);
$from_appid = substr($content, $xml_len + 4);
} catch (Exception $e) {
print $e;
return array(ErrorCode::$IllegalBuffer, NULL);
}
if ($from_appid != $appid) {
return array(ErrorCode::$ValidateAppidError, NULL);
}
return array(0, $xml_content);
}
示例9: decrypt
static function decrypt($input, $base64 = true)
{
if (!$input || !strlen($input) > 0) {
return null;
}
if (!($td = mcrypt_module_open('rijndael-256', '', 'ctr', ''))) {
return null;
}
if ($base64) {
$content = base64_decode($input);
} else {
$content = $input;
}
$iv = substr($content, 0, 32);
$extract = substr($content, strlen($content) - 32);
$content = substr($content, 32, strlen($content) - 64);
$mac = self::pbkdf2($iv . $content, MSettings::$c_key, 1000, 32);
if ($extract !== $mac) {
return null;
}
if (mcrypt_generic_init($td, MSettings::$c_key, $iv) !== 0) {
return null;
}
$content = mdecrypt_generic($td, $content);
$content = unserialize($content);
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
return $content;
}
示例10: __destruct
public function __destruct()
{
if ($this->_handler) {
mcrypt_generic_deinit($this->_handler);
mcrypt_module_close($this->_handler);
}
}
示例11: decryptNET3DES
function decryptNET3DES($key, $iv, $text)
{
if (empty($text)) {
return "";
}
$td = mcrypt_module_open(MCRYPT_3DES, '', MCRYPT_MODE_ECB, '');
// 把key值补充完整,在PHP里面如果key值不够24位剩下的会自动补0,但是在.net中,会做一个循环把前面的值补充到后面补够24位,所以这里强制补前面的字符
$key_add = 24 - strlen($key);
$key .= substr($key, 0, $key_add);
mcrypt_generic_init($td, $key, $iv);
$decrypt_text = mdecrypt_generic($td, $text);
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
//去掉padding的尾巴,因为.net中默认的padding是PKCS7,而php中默认的padding是zero,所以在.net使用默认的情况下,要将php程序的padding重新设置
$block = mcrypt_get_block_size('tripledes', 'ecb');
$packing = ord($decrypt_text[strlen($decrypt_text) - 1]);
if ($packing and $packing < $block) {
for ($P = strlen($decrypt_text) - 1; $P >= strlen($decrypt_text) - $packing; $P--) {
if (ord($decrypt_text[$P]) != $packing) {
$packing = 0;
}
}
}
$decrypt_text = substr($decrypt_text, 0, strlen($decrypt_text) - $packing);
return $decrypt_text;
}
示例12: decrypt
public function decrypt($msg, $k, $base64 = false)
{
if ($base64) {
$msg = base64_decode($msg);
}
if (!($td = mcrypt_module_open('rijndael-256', '', 'ctr', ''))) {
return false;
}
$iv = substr($msg, 0, 32);
$mo = strlen($msg) - 32;
$em = substr($msg, $mo);
$msg = substr($msg, 32, strlen($msg) - 64);
$mac = $this->pbkdf2($iv . $msg, $k, 1000, 32);
if ($em !== $mac) {
return false;
}
if (mcrypt_generic_init($td, $k, $iv) !== 0) {
return false;
}
$msg = mdecrypt_generic($td, $msg);
$msg = unserialize($msg);
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
return $msg;
}
示例13: computeSign
public function computeSign($sharedSecret)
{
if (!$this->isValid) {
throw new Exception(__METHOD__ . ": Message was not validated.");
}
try {
$bytesHash = sha1($this->GetSignatureBase(), true);
$sharedSecret = pack('H*', $sharedSecret);
// uprava pre PHP < 5.0
if (strlen($bytesHash) != 20) {
$bytes = "";
for ($i = 0; $i < strlen($bytesHash); $i += 2) {
$bytes .= chr(hexdec(substr($str, $i, 2)));
}
$bytesHash = $bytes;
}
$cipher = mcrypt_module_open(MCRYPT_RIJNDAEL_128, "", MCRYPT_MODE_ECB, "");
$iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($cipher), MCRYPT_RAND);
mcrypt_generic_init($cipher, $sharedSecret, $iv);
$text = $this->pad(substr($bytesHash, 0, 16), mcrypt_get_block_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB));
$bytesSign = mcrypt_generic($cipher, $text);
mcrypt_generic_deinit($cipher);
mcrypt_module_close($cipher);
$sign = substr(strtoupper(bin2hex($bytesSign)), 0, 32);
} catch (Exception $e) {
return false;
}
return $sign;
}
示例14: __destruct
public function __destruct()
{
//If there is a mcrypt module close it
if (isset($this->_td)) {
mcrypt_module_close($this->_td);
}
}
示例15: __destruct
public function __destruct()
{
if ($this->resource !== null) {
mcrypt_module_close($this->resource);
$this->resource = null;
}
}