用了php5.5 银联接口netpayclient.php 的mcrypt_cbc不能用了,该怎么替换?
// This file is protected by copyright law & provided under license. Copyright(C) 2005-2009 www.chinapay.com, All rights reserved.// This file is protected by copyright law & provided under license. Copyright(C) 2005-2009 www.chinapay.com, All rights reserved.define("DES_KEY", "SCUBEPGW");define("HASH_PAD", "0001ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff003021300906052b0e03021a05000414");bcscale(0);$private_key = array(); /*function hex2bin($hexdata) { $bindata = ''; if (strlen($hexdata) % 2 == 1) { $hexdata = '0' . $hexdata; } for ($i = 0; $i < strlen($hexdata); $i+=2) { $bindata .= chr(hexdec(substr($hexdata, $i, 2))); } return $bindata;}*/ function padstr($src, $len = 256, $chr = '0', $d = 'L') { $ret = trim($src); $padlen = $len - strlen($ret); if ($padlen > 0) { $pad = str_repeat($chr, $padlen); if (strtoupper($d) == 'L') { $ret = $pad . $ret; } else { $ret = $ret . $pad; } } return $ret;} function bin2int($bindata) { $hexdata = bin2hex($bindata); return bchexdec($hexdata);} function bchexdec($hexdata) { $ret = '0'; $len = strlen($hexdata); for ($i = 0; $i < $len; $i++) { $hex = substr($hexdata, $i, 1); $dec = hexdec($hex); $exp = $len - $i - 1; $pow = bcpow('16', $exp); $tmp = bcmul($dec, $pow); $ret = bcadd($ret, $tmp); } return $ret;} function bcdechex($decdata) { $s = $decdata; $ret = ''; while ($s != '0') { $m = bcmod($s, '16'); $s = bcdiv($s, '16'); $hex = dechex($m); $ret = $hex . $ret; } return $ret;} function sha1_128($string) { $hash = sha1($string); $sha_bin = hex2bin($hash); $sha_pad = hex2bin(HASH_PAD); return $sha_pad . $sha_bin;} function mybcpowmod($num, $pow, $mod) { if (function_exists('bcpowmod')) { return bcpowmod($num, $pow, $mod); } return emubcpowmod($num, $pow, $mod);} function emubcpowmod($num, $pow, $mod) { $result = '1'; do { if (!bccomp(bcmod($pow, '2'), '1')) { $result = bcmod(bcmul($result, $num), $mod); } $num = bcmod(bcpow($num, '2'), $mod); $pow = bcdiv($pow, '2'); } while (bccomp($pow, '0')); return $result;} function rsa_encrypt($private_key, $input) { $p = bin2int($private_key["prime1"]); $q = bin2int($private_key["prime2"]); $u = bin2int($private_key["coefficient"]); $dP = bin2int($private_key["prime_exponent1"]); $dQ = bin2int($private_key["prime_exponent2"]); $c = bin2int($input); $cp = bcmod($c, $p); $cq = bcmod($c, $q); $a = mybcpowmod($cp, $dP, $p); $b = mybcpowmod($cq, $dQ, $q); if (bccomp($a, $b) >= 0) { $result = bcsub($a, $b); } else { $result = bcsub($b, $a); $result = bcsub($p, $result); } $result = bcmod($result, $p); $result = bcmul($result, $u); $result = bcmod($result, $p); $result = bcmul($result, $q); $result = bcadd($result, $b); $ret = bcdechex($result); $ret = strtoupper(padstr($ret)); return (strlen($ret) == 256) ? $ret : false;} function rsa_decrypt($input) { global $private_key; $check = bchexdec($input); $modulus = bin2int($private_key["modulus"]); $exponent = bchexdec("010001"); $result = bcpowmod($check, $exponent, $modulus); $rb = bcdechex($result); return strtoupper(padstr($rb));} function buildKey($key) { global $private_key; if (count($private_key) > 0) { foreach ($private_key as $name => $value) { unset($private_key[$name]); } } $ret = false; $key_file = parse_ini_file($key); if (!$key_file) { return $ret; } $hex = ""; if (array_key_exists("MERID", $key_file)) { $ret = $key_file["MERID"]; $private_key["MERID"] = $ret; $hex = substr($key_file["prikeyS"], 80); } else if (array_key_exists("PGID", $key_file)) { $ret = $key_file["PGID"]; $private_key["PGID"] = $ret; $hex = substr($key_file["pubkeyS"], 48); } else { return $ret; } $bin = hex2bin($hex); $private_key["modulus"] = substr($bin, 0, 128); $cipher = MCRYPT_DES; $iv = str_repeat("\x00", 8); $prime1 = substr($bin, 384, 64); $enc = mcrypt_cbc($cipher, DES_KEY, $prime1, MCRYPT_DECRYPT, $iv); $private_key["prime1"] = $enc; $prime2 = substr($bin, 448, 64); $enc = mcrypt_cbc($cipher, DES_KEY, $prime2, MCRYPT_DECRYPT, $iv); $private_key["prime2"] = $enc; $prime_exponent1 = substr($bin, 512, 64); $enc = mcrypt_cbc($cipher, DES_KEY, $prime_exponent1, MCRYPT_DECRYPT, $iv); $private_key["prime_exponent1"] = $enc; $prime_exponent2 = substr($bin, 576, 64); $enc = mcrypt_cbc($cipher, DES_KEY, $prime_exponent2, MCRYPT_DECRYPT, $iv); $private_key["prime_exponent2"] = $enc; $coefficient = substr($bin, 640, 64); $enc = mcrypt_cbc($cipher, DES_KEY, $coefficient, MCRYPT_DECRYPT, $iv); $private_key["coefficient"] = $enc; return $ret;} function sign($msg) { global $private_key; if (!array_key_exists("MERID", $private_key)) { return false; } $hb = sha1_128($msg); return rsa_encrypt($private_key, $hb);} function signOrder($merid, $ordno, $amount, $curyid, $transdate, $transtype) { if (strlen($merid) != 15) return false; if (strlen($ordno) != 16) return false; if (strlen($amount) != 12) return false; if (strlen($curyid) != 3) return false; if (strlen($transdate) != 8) return false; if (strlen($transtype) != 4) return false; $plain = $merid . $ordno . $amount . $curyid . $transdate . $transtype; return sign($plain);} function verify($plain, $check) { global $private_key; if (!array_key_exists("PGID", $private_key)) { return false; } if (strlen($check) != 256) { return false; } $hb = sha1_128($plain); $hbhex = strtoupper(bin2hex($hb)); $rbhex = rsa_decrypt($check); return $hbhex == $rbhex ? true : false;} function verifyTransResponse($merid, $ordno, $amount, $curyid, $transdate, $transtype, $ordstatus, $check) { if (strlen($merid) != 15) return false; if (strlen($ordno) != 16) return false; if (strlen($amount) != 12) return false; if (strlen($curyid) != 3) return false; if (strlen($transdate) != 8) return false; if (strlen($transtype) != 4) return false; if (strlen($ordstatus) != 4) return false; if (strlen($check) != 256) return false; $plain = $merid . $ordno . $amount . $curyid . $transdate . $transtype . $ordstatus; return verify($plain, $check);}
回复讨论(解决方案)
自PHP 5.5.0起,此函数已经被废弃。强烈建议不要使用此函数 。
http://www.php.net/manual/zh/function.mcrypt-cbc.php
我知道弃用了,但是银联的接口用的就是这个,我想知道怎么改,谢谢

使用數據庫存儲會話的主要優勢包括持久性、可擴展性和安全性。 1.持久性:即使服務器重啟,會話數據也能保持不變。 2.可擴展性:適用於分佈式系統,確保會話數據在多服務器間同步。 3.安全性:數據庫提供加密存儲,保護敏感信息。

在PHP中實現自定義會話處理可以通過實現SessionHandlerInterface接口來完成。具體步驟包括:1)創建實現SessionHandlerInterface的類,如CustomSessionHandler;2)重寫接口中的方法(如open,close,read,write,destroy,gc)來定義會話數據的生命週期和存儲方式;3)在PHP腳本中註冊自定義會話處理器並啟動會話。這樣可以將數據存儲在MySQL、Redis等介質中,提升性能、安全性和可擴展性。

SessionID是網絡應用程序中用來跟踪用戶會話狀態的機制。 1.它是一個隨機生成的字符串,用於在用戶與服務器之間的多次交互中保持用戶的身份信息。 2.服務器生成並通過cookie或URL參數發送給客戶端,幫助在用戶的多次請求中識別和關聯這些請求。 3.生成通常使用隨機算法保證唯一性和不可預測性。 4.在實際開發中,可以使用內存數據庫如Redis來存儲session數據,提升性能和安全性。

在無狀態環境如API中管理會話可以通過使用JWT或cookies來實現。 1.JWT適合無狀態和可擴展性,但大數據時體積大。 2.Cookies更傳統且易實現,但需謹慎配置以確保安全性。

要保護應用免受與會話相關的XSS攻擊,需採取以下措施:1.設置HttpOnly和Secure標誌保護會話cookie。 2.對所有用戶輸入進行輸出編碼。 3.實施內容安全策略(CSP)限制腳本來源。通過這些策略,可以有效防護會話相關的XSS攻擊,確保用戶數據安全。

优化PHP会话性能的方法包括:1.延迟会话启动,2.使用数据库存储会话,3.压缩会话数据,4.管理会话生命周期,5.实现会话共享。这些策略能显著提升应用在高并发环境下的效率。

theSession.gc_maxlifetimesettinginphpdeterminesthelifespanofsessiondata,setInSeconds.1)它'sconfiguredinphp.iniorviaini_set().2)abalanceisesneededeededeedeedeededto toavoidperformance andunununununexpectedLogOgouts.3)

在PHP中,可以使用session_name()函數配置會話名稱。具體步驟如下:1.使用session_name()函數設置會話名稱,例如session_name("my_session")。 2.在設置會話名稱後,調用session_start()啟動會話。配置會話名稱可以避免多應用間的會話數據衝突,並增強安全性,但需注意會話名稱的唯一性、安全性、長度和設置時機。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

mPDF
mPDF是一個PHP庫,可以從UTF-8編碼的HTML產生PDF檔案。原作者Ian Back編寫mPDF以從他的網站上「即時」輸出PDF文件,並處理不同的語言。與原始腳本如HTML2FPDF相比,它的速度較慢,並且在使用Unicode字體時產生的檔案較大,但支援CSS樣式等,並進行了大量增強。支援幾乎所有語言,包括RTL(阿拉伯語和希伯來語)和CJK(中日韓)。支援嵌套的區塊級元素(如P、DIV),

VSCode Windows 64位元 下載
微軟推出的免費、功能強大的一款IDE編輯器

記事本++7.3.1
好用且免費的程式碼編輯器

PhpStorm Mac 版本
最新(2018.2.1 )專業的PHP整合開發工具

ZendStudio 13.5.1 Mac
強大的PHP整合開發環境