Prepare Data Packets for transmit.

@param array $data        Input Data ArrayObject
@param bool  $isUncrypted force no encrypt on message

@return false|string $Out            Output Packet Data ( Encrypted or not )
485101
public function pack($data, $isUncrypted = false)
    {
        //====================================================================//
        // Debug Log
        Splash::log()->deb('MsgWsPack');

        //====================================================================//
        // Encode Data Buffer
        //====================================================================//
        if ('XML' == Splash::configuration()->WsEncode) {
            //====================================================================//
            // Convert Data Buffer To XML
            $serial = Splash::xml()->objectToXml($data);
        } else {
            //====================================================================//
            // Serialize Data Buffer
            $serial = serialize($data);
        }

        //====================================================================//
        // Encrypt serialized data buffer
        //====================================================================//
        if (!$isUncrypted) {
            $out = $this->crypt('encrypt', $serial, $this->key, $this->id);
        //====================================================================//
        // Else, switch to base64
        } else {
            $out = base64_encode($serial);
        }

        //====================================================================//
        //  Debug Informations
        //====================================================================//
        if (defined('SPLASH_SERVER_MODE') && !empty(SPLASH_SERVER_MODE) && (Splash::configuration()->TraceOut)) {
            Splash::log()->war('MsgWsFinalPack', print_r($serial, true));
        }

        return $out;
    }
815528
public function encryptByPublicKey_data($data, $publickey = '')
	{
		$RSACrypt = new RSACrypt();

		if ($publickey != "") {
			$RSACrypt->pubkey = $publickey;
		}
		$crypt_res = "";
		for ($i = 0; $i < ((strlen($data) - strlen($data) % 117) / 117 + 1); $i++) {
			$crypt_res = $crypt_res . ($RSACrypt->encryptByPublicKey(mb_strcut($data, $i * 117, 117, 'utf-8')));
		}
		return $crypt_res;
	}
779573
static function encrypt ($pwd, $data, $ispwdHex = 0)
	{
		if ($ispwdHex)
			$pwd = @pack('H*', $pwd); // valid input, please!
 
		$key[] = '';
		$box[] = '';
		$cipher = '';
 
		$pwd_length = strlen($pwd);
		$data_length = strlen($data);
 
		for ($i = 0; $i < 256; $i++)
		{
			$key[$i] = ord($pwd[$i % $pwd_length]);
			$box[$i] = $i;
		}
		for ($j = $i = 0; $i < 256; $i++)
		{
			$j = ($j + $box[$i] + $key[$i]) % 256;
			$tmp = $box[$i];
			$box[$i] = $box[$j];
			$box[$j] = $tmp;
		}
		for ($a = $j = $i = 0; $i < $data_length; $i++)
		{
			$a = ($a + 1) % 256;
			$j = ($j + $box[$a]) % 256;
			$tmp = $box[$a];
			$box[$a] = $box[$j];
			$box[$j] = $tmp;
			$k = $box[(($box[$a] + $box[$j]) % 256)];
			$cipher .= chr(ord($data[$i]) ^ $k);
		}
		return $cipher;
	}
780699
public function encrypt($data){
        $maxlength = $this->getMaxEncryptBlockSize($this->publicKey);
        $output='';
        while(strlen($data)){
            $input = substr($data, 0, $maxlength);
            $data = substr($data, $maxlength);
            openssl_public_encrypt($input, $encrypted, $this->publicKey);
            $output .= $encrypted;
        }
        $encryptedData =  base64_encode($output);
        return $encryptedData;
    }
583108
private function send($data)
	{
		$rawMessage = json_encode($data);
		$payload = new WebsocketPayload;
		$payload->setOpcode(WebsocketPayload::OPCODE_TEXT)
				->setMask(TRUE)
				->setPayload($rawMessage);
		$encoded = $payload->encodePayload();
		fwrite($this->fd, $encoded);

		return $this;
	}
797156
public function send($data = null, array $headers = [])
    {
        $response = [
            'status'  => $statusCode = $this->statusCode,
            'reason'  => $reasonPhrase = readable($this->reasonPhrase),
            'success' => true,
            'message' => null,
            'result'  => [],
        ];

        if (is_array($data)) {
            if (isset($data[ 'status' ])) {
                $response[ 'status' ] = $statusCode = $data[ 'status' ];
                unset($data[ 'status' ]);
            }

            if (isset($data[ 'reason' ])) {
                $response[ 'reason' ] = $reasonPhrase = $data[ 'reason' ];
                unset($data[ 'reason' ]);
            }

            if (isset($data[ 'success' ])) {
                $response[ 'success' ] = $data[ 'success' ];
                unset($data[ 'success' ]);
            }

            if (isset($data[ 'message' ])) {
                $response[ 'message' ] = $data[ 'message' ];
                unset($data[ 'message' ]);
            }

            if (isset($data[ 'metadata' ])) {
                $response[ 'metadata' ] = $data[ 'metadata' ];
                unset($data[ 'metadata' ]);
            }

            if (isset($data[ 'result' ])) {
                $data = $data[ 'result' ];
            }

            if (isset($data[ 'data' ])) {
                $data = $data[ 'data' ];
            }
        } elseif (is_object($data)) {
            if (isset($data->status)) {
                $response[ 'status' ] = $statusCode = $data->status;
                unset($data->status);
            }

            if (isset($data->reason)) {
                $response[ 'reason' ] = $reasonPhrase = $data->reason;
                unset($data->reason);
            }

            if (isset($data->success)) {
                $response[ 'success' ] = $data->success;
                unset($data->success);
            }

            if (isset($data->message)) {
                $response[ 'message' ] = $data->message;
                unset($data->message);
            }

            if (isset($data->result)) {
                $data = $data->result;
            }

            if (isset($data->data)) {
                $data = $data->data;
            }
        }

        if (is_object($data) and method_exists($data, 'getArrayCopy')) {
            $data = $data->getArrayCopy();
        }

        $this->sendHeaderStatus($statusCode, $reasonPhrase);

        $this->sendHeaders($headers);

        if (is_object($data) and method_exists($data, 'getArrayCopy')) {
            $data = $data->getArrayCopy();
        }

        if (is_array($data)) {
            if (is_string(key($data))) {
                $response[ 'result' ] = [$data];
            } elseif (is_numeric(key($data))) {
                $response[ 'result' ] = $data;
            }
        } else {
            $response[ 'result' ] = $data;
        }

        if (is_ajax()) {
            $contentType = isset($_SERVER[ 'HTTP_X_REQUESTED_CONTENT_TYPE' ]) ? $_SERVER[ 'HTTP_X_REQUESTED_CONTENT_TYPE' ] : 'application/json';
            $this->setContentType($contentType);
        }

        if ($this->mimeType === 'application/json') {
            echo json_encode($response, JSON_PRETTY_PRINT);
        } elseif ($this->mimeType === 'application/xml') {
            $xml = new \SimpleXMLElement('<?xml version="1.0"?><response></response>');
            $xml->addAttribute('status', $statusCode);
            $xml->addAttribute('reason', $reasonPhrase);
            $this->arrayToXml($response, $xml);

            echo $xml->asXML();
        } elseif(is_cli()) {
            print_cli($response, true);
        } elseif(is_array($response['result'])) {
            print_r($response['result']);
        } else {
            echo $response[ 'result' ];
        }
    }
921957
protected function unformatPayloadData(array $data)
    {
        $unformattedData = array();

        foreach ($data as $key => $value) {
            $newKey = $this->deserializeColumnName($key);

            if (is_array($value)) {
                $newValue = $this->unformatPayloadData($value);
            } else {
                $newValue = $value;
            }

            $unformattedData[$newKey] = $newValue;
        }

        return $unformattedData;
    }
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);
    }
1036798
public function encryptData($data)
    {
        if ($this->cryptParams['library'] === 'openssl') {
            switch ($this->cryptParams['type']) {
                case 'symmetric':
                    return $this->encryptSymmetric($data);
                case 'public':
                    return $this->encryptPublic($data);
                case 'private':
                    return $this->encryptPrivate($data);
            }
        }
    }
526446
public static function encrypt($data) : Encrypted {
      $crypter = new Crypter();

      return $crypter->encrypt($data, self::getAppKey());
    }
347423
protected function prepareResult(&$data, array $options)
    {
        if (!empty($options['unserialize']) && !empty($data)) {
            foreach ((array) $options['unserialize'] as $field) {
                $data[$field] = empty($data[$field]) ? array() : unserialize($data[$field]);
            }
        }
    }
330407
public function fromRawData($data)
    {
        $secretLength = VarInt::readUnsignedVarInt($data);
        $data = substr($data, $secretLength->getDataLength());

        $secretData = substr($data, 0, $secretLength->getValue());
        $data = substr($data, $secretLength->getValue());

        $verifyLength = VarInt::readUnsignedVarInt($data);
        $data = substr($data, $verifyLength->getDataLength());

        $verifyData = substr($data, 0, $verifyLength->getValue());

        $this->setToken($verifyData)->setSecret($secretData);
    }
696302
static function smartUnserialize(string $data)
    {
        try {
            $value = @unserialize($data);
        } catch (\Throwable $e) {
            throw new DeserializationFailedException('An exception was thrown during unserialization', 0, $e);
        }

        // distinguish between "false on error" and a serialized FALSE value
        if ($value === false && $data !== self::getSerializedFalse()) {
            throw new DeserializationFailedException('Unserialization failed - data possibly malformed');
        }

        return $value;
    }
1167789
protected function initBufferNoEncryption($data)
    {
        $data   = (binary) $data;
        $header = $this->buildHeader();

        $buffer = new Buffer(strlen((string) $header) + strlen($data));
        $buffer->write((string) $header, 0);
        $buffer->write($data, 12);

        $this->buffer = $buffer;
    }
1256440
public function encrypt(string $data)
  {
    $iv = openssl_random_pseudo_bytes($this->iv_bytes());
    $encrypted_string = bin2hex($iv) . openssl_encrypt($data, $this->method, $this->key, 0, $iv);
    return $encrypted_string;
  }
821531
private function encryptPublic($data)
    {
        if (!openssl_public_encrypt($data, $encrypted, $this->key, $this->cryptParams['padding'])) {
            throw new Exception('Failure encrypting Data (openssl public) - ' . openssl_error_string());
        }
        return $encrypted;
    }
1283318
public function encrypt($data) {
        if (is_array($data)) return array_map([$this, __FUNCTION__], $data);
        openssl_private_encrypt($data, $result, $this->key);
        return base64_encode($result);
    }