Convert a hexadecimal string into raw binary

@param string $data Hexadecimal data

@return string
498446
public static function hexToBin($data)
    {
        if (self::ourStrlen($data) % 2 !== 0) {
            \trigger_error("hex2bin(): Hexadecimal input string must have an even length", E_USER_WARNING);
            return false;
        }
        return \pack('H*', $data);
    }
784319
protected static function checksum($data)
    {
        $bit = unpack('n*', $data);
        $sum = array_sum($bit);
        if (mb_orig_strlen($data) % 2) {
            $temp = unpack('C*', $data[mb_orig_strlen($data) - 1]);
            $sum += $temp[1];
        }
        $sum = ($sum >> 16) + ($sum & 0xffff);
        $sum += ($sum >> 16);
        return pack('n*', ~$sum);
    }
21517
private function encrypt(string $data): string
    {
        $cipher = Cryptography::encrypt($data, $this->cryptKey);
        list($initializationVector, $cipher) = explode(':', $cipher);
        $initializationVector = base64_decode($initializationVector);
        $cipher = base64_decode($cipher);
        $content = $initializationVector . Cryptography::getEncryptionAlgorithm() . $cipher;
        $hmac = hash_hmac('sha256', $content, $this->cryptAuth);
        return $hmac . ':' . base64_encode($initializationVector) . ':' . base64_encode($cipher);
    }
1151778
public function unserialize($data)
    {
        $serializer = $this->_serializer;

        if ($serializer === 'php') {
            $r = [];
            $offset = 0;
            while ($offset < strlen($data)) {
                if (strpos(substr($data, $offset), '|') === false) {
                    return false;
                }
                $pos = strpos($data, '|', $offset);
                $num = $pos - $offset;
                $key = substr($data, $offset, $num);
                $offset += $num + 1;
                $value = unserialize(substr($data, $offset));
                $r[$key] = $value;
                $offset += strlen(serialize($value));
            }
            return $r;
        } elseif ($serializer === 'php_binary') {
            $r = [];
            $offset = 0;
            while ($offset < strlen($data)) {
                $num = ord($data[$offset]);
                $offset++;
                $key = substr($data, $offset, $num);
                $offset += $num;
                $value = unserialize(substr($data, $offset));
                $r[$key] = $value;
                $offset += strlen(serialize($value));
            }
            return $r;
        } elseif ($serializer === 'php_serialize') {
            return unserialize($data);
        } elseif ($serializer === 'json') {
            return json_decode($data, true);
        } elseif ($serializer === 'igbinary') {
            return igbinary_unserialize($data);
        } elseif ($serializer === 'wddx') {
            return wddx_deserialize($data);
        } else {
            throw new InvalidOptionException(['`:serializer` serializer is not support', 'serializer' => $serializer]);
        }
    }
1210696
protected function unserialize(string $data)
    {
        $unserializedData = json_decode($data, true);
        $unserializedData['d'] = unserialize($unserializedData['d']);

        return $unserializedData;
    }
875962
static String toHex(byte[] data) {

        StringBuffer sb = new StringBuffer(data.length*2);

        for (int i=0; i<data.length; i++) {
            sb.append(hexc[(data[i] >>4) & 0x0f]);
            sb.append(hexc[data[i] & 0x0f]);
        }
        return sb.toString();
    }
226798
private function unserialize(string $data)
    {
        $value = unserialize($data);

        if ($this->packer !== null) {
            return $this->packer->unpack($value);
        }

        return $value;
    }
1060041
public function encrypt($data)
    {
        return base64_encode(openssl_encrypt($data, $this->cipher, $this->key, 0, $this->iv).'&&'.bin2hex($this->iv));
    }
744975
public function convertToString($data) {
		if (!is_string($data)) {
			$data = @json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
			// Removing null byte and double slashes from object properties
			$data = str_replace(['\\u0000', '\\\\'], ["", "\\"], $data);
		}

		return $data;
	}
522502
private function safe_decode($data) {
    if (is_array($data)) {
      return array_map(array($this, 'safe_decode'), $data);
    } else if (is_scalar($data)) {
      return rawurldecode($data);
    } else {
      return '';
    }
  }
1163898
public function encrypt($data)
	{
		if (!$this->encEnabled) return $data; // no encryption
		switch ($this->encMethod) {
			case 'SIMPLE':
				return $this->encryptSimple($data);
			case 'INTEGER':
				return $this->encryptInteger($data);
		}
		if ($this->iv) {
			$iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length($this->encMethod));
		} else {
			$iv=substr(md5($data,true),0,openssl_cipher_iv_length($this->encMethod));
		}
		$encrypted_string = bin2hex($iv) . openssl_encrypt($this->encSalt . $data, $this->encMethod, $this->encPassword, 0, $iv);
		return str_replace(array('+', '/'), array('-', '_'),base64_encode($encrypted_string));
	}
1185083
public static function decode(string $data): string
    {
        $decoded = base64_decode(strtr($data, '-_', '+/'), true);
        if (false === $decoded) {
            throw new InvalidArgumentException('Invalid data provided');
        }

        return $decoded;
    }
1007671
public function serialize($data)
    {
        $serializer = $this->_serializer;

        //https://github.com/wikimedia/php-session-serializer/blob/master/src/Wikimedia/PhpSessionSerializer.php
        if ($serializer === 'php') {
            $r = '';
            foreach ($data as $key => $value) {
                $v = serialize($value);
                $r .= "$key|$v";
            }
            return $r;
        } elseif ($serializer === 'php_binary') {
            $r = '';
            foreach ($data as $key => $value) {
                $r .= chr(strlen($key)) . $key . serialize($value);
            }
            return $r;
        } elseif ($serializer === 'php_serialize') {
            return $this->serialize($data);
        } elseif ($serializer === 'json') {
            return json_encode($data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
        } elseif ($serializer === 'igbinary') {
            return igbinary_serialize($data);
        } elseif ($serializer === 'wddx') {
            return wddx_serialize_value($data);
        } else {
            throw new InvalidOptionException(['`:serializer` serializer is not support', 'serializer' => $serializer]);
        }
    }
72895
protected function encrypt($data)
    {
        $salt = random_bytes(16);

        $salted = hash('sha512', $this->key . $salt, true);
        $key    = substr($salted, 0, 32);
        $iv     = substr($salted, 32, 16);

        $encryptedData = openssl_encrypt($data, 'AES-256-CBC', $key, OPENSSL_RAW_DATA, $iv);
        return base64_encode($salt . $encryptedData);
    }
624891
public function encode($data)
    {
        $result = '';
        foreach($data as $k => $v)
        {
            $result .= $k . '|' . serialize($v);
        }
        return $result;
    }
802356
private function _generateUUIDFromData($data)
    {
        $data = substr($data, 0, 16);

        $data[6] = chr(ord($data[6]) & 0x0f | 0x40); // set the '4' in block 3
        $data[8] = chr(ord($data[8]) & 0x3f | 0x80); // set bits for block 4

        return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4));
    }
1117697
function decryptSimple($data) {
		$result = '';
		$data=base64_decode(str_replace(array('-', '_'),array('+', '/'),$data));
		for($i=0; $i<strlen($data); $i++) {
			$char = substr($data, $i, 1);
			$keychar = substr($this->encPassword, ($i % strlen($this->encPassword))-1, 1);
			$char = chr(ord($char)-ord($keychar));
			$result.=$char;
		}
		return $result;
	}