/** * 3DES 解密 进行了补位的16进制表示的字符串数据 * * @return * */ public static function decrypt4HexStr($keys, $data) { $hexSourceData = array(); $hexSourceData = ByteUtils::hexStrToBytes($data); //var_dump($hexSourceData); // 解密 $unDesResult = TDESUtil::decrypt(ByteUtils::toStr($hexSourceData), $keys); //echo $unDesResult; $unDesResultByte = ByteUtils::getBytes($unDesResult); //var_dump($unDesResultByte); $dataSizeByte = array(); for ($i = 0; $i < 4; $i++) { $dataSizeByte[$i] = $unDesResultByte[$i]; } // 有效数据长度 $dsb = ByteUtils::byteArrayToInt($dataSizeByte, 0); $tempData = array(); for ($j = 0; $j < $dsb; $j++) { $tempData[$j] = $unDesResultByte[4 + $j]; } return ByteUtils::hexTobin(ByteUtils::bytesToHex($tempData)); }
public static function bytesToHex($bytes) { $str = ByteUtils::toStr($bytes); return ByteUtils::strToHex($str); }
function writeList(&$value) { if ($this->writeReference($value)) { return; } $this->stream .= 'V'; // type, maybe we don't need type info since this is PHP $this->stream .= 't'; $this->writeStringData(''); // end type info if (!empty($value)) { $this->stream .= 'l'; $this->stream .= ByteUtils::getIntBytes(count($value), 32); foreach ($value as $val) { $this->writeObject($val); } } $this->stream .= 'z'; }