Given the 'certData' string, turn it back into a proper PEM encoded certificate.

@param string $certData
@return string
177170
private function formatKey($certData)
    {
        return X509Certificate::PEM_HEADER .
            PHP_EOL .
            // Chunk it in 64 character bytes
            chunk_split($certData, 64, PHP_EOL) .
            X509Certificate::PEM_FOOTER .
            PHP_EOL;
    }
211975
private function calculateHmac($securedData) {
		$decodedSecret = base64_decode($this->applicationKey);
		return base64_encode(hash_hmac("sha512", $securedData, $decodedSecret, true));
	}
764186
public function encrypt($strData)
    {
        $strEncryptedData = openssl_encrypt($strData, $this->strCipher, $this->strKey, 0, $this->strIv);

        if ($this->strIvHashKey) {
            // User has asked to include the IV with the encrypted string so that we do not have to store the IV somewhere else.
            /**
             * Based on http://pastebin.com/sN6buivY
             * True will append the initialization vector and a hash value to the end of the cryptography so that:
             * a) The crypto can be unencrypted without having to save the IV
             * b) The crypto can be tested for tampering using the hash.
             *
             * Will increase the size of the resulting value by the size of the IV + about 50%. The other option is to serialize the class or in
             * some other way save the IV and restore it later.
             */
            $strEncryptedData .= ':' . bin2hex($this->strIv);
            $strEncryptedData .= ':' . hash_hmac('sha256', $strEncryptedData, $this->strIvHashKey);
        }

        if ($this->blnBase64) {
            $strEncryptedData = QString::base64UrlSafeEncode($strEncryptedData);
        }

        return $strEncryptedData;
    }
284499
public function create($certificateData, $options = array()) {
        $options = new Values($options);

        $data = Values::of(array(
            'CertificateData' => $certificateData,
            'FriendlyName' => $options['friendlyName'],
            'DeviceSid' => $options['deviceSid'],
        ));

        $payload = $this->version->create(
            'POST',
            $this->uri,
            array(),
            $data
        );

        return new CertificateInstance($this->version, $payload, $this->solution['fleetSid']);
    }
84186
public function encode($data)
    {
        return openssl_encrypt($data, $this->method, $this->key, 0, $this->iv);
    }
614030
public function validateRequestSignature($requestData) {
		$certKey = openssl_pkey_get_public($this->certificateContent);
		$valid   = openssl_verify($requestData, base64_decode($this->requestSignature), $certKey, self::ENCRYPT_METHOD);
		if (!$valid) {
			throw new InvalidArgumentException('Request signature could not be verified');
		}

		return true;
	}
471761
public function sign($data)
    {
        $privateKeyResource = openssl_pkey_get_private('file://' . $this->filePath);

        $signature = null;
        openssl_sign($data, $signature, $privateKeyResource);

        openssl_free_key($privateKeyResource);

        return $signature;
    }
1246993
private function readByteStringLong($subData)
    {
        // offset: 0; size: 2; length of the string (character count)
        $ln = self::getInt2d($subData, 0);

        // offset: 2: size: var; character array (8-bit characters)
        $value = $this->decodeCodepage(substr($subData, 2));

        //return $string;
        return array(
            'value' => $value,
            'size' => 2 + $ln, // size in bytes of data structure
        );
    }
427434
private function _readByteStringShort($subData)
	{
		// offset: 0; size: 1; length of the string (character count)
		$ln = ord($subData[0]);

		// offset: 1: size: var; character array (8-bit characters)
		$value = $this->_decodeCodepage(substr($subData, 1, $ln));

		return array(
			'value' => $value,
			'size' => 1 + $ln, // size in bytes of data structure
		);
	}
393565
public static function encode($jsonData)
    {
        $jsonString = json_encode($jsonData);
        // 5.5.0 	The return value on failure was changed from null string to FALSE.
        if (false === $jsonString || 'null' === $jsonString) {
            throw new JsonException('unable to encode JSON');
        }

        return $jsonString;
    }
384207
public function decode($data)
    {
        if ($this->extensionLoaded()) {
            $oData = $data;
            $data = @((\strlen($data) > 0) ? \gzuncompress($data) : '');
            if ($data === false) {
                // Try this fallback
                $tries = 1;
                while ($tries < 10 && ($data === false || \strlen($data) < (\strlen($oData) - $tries - 1))) {
                    $data = @(\gzinflate(\substr($oData, $tries)));
                    $tries++;
                }

                if ($data === false) {
                    // let's try if the checksum is CRC32
                    $fh = fopen('php://temp', 'w+b');
                    \fwrite($fh, "\x1f\x8b\x08\x00\x00\x00\x00\x00" . $oData);
                    \stream_filter_append($fh, 'zlib.inflate', \STREAM_FILTER_READ, ['window' => 30]);
                    \fseek($fh, 0);
                    $data = \stream_get_contents($fh);
                    \fclose($fh);
                }

                if (!$data) {
                    throw new FlateException(
                        'Error while decompressing stream.',
                        FlateException::DECOMPRESS_ERROR
                    );
                }
            }
        } else {
            throw new FlateException(
                'To handle FlateDecode filter, enable zlib support in PHP.',
                FlateException::NO_ZLIB
            );
        }

        return $data;
    }
124801
public static byte[] getEncodedInternal(Certificate cert)
            throws CertificateEncodingException {
        if (cert instanceof X509CertImpl) {
            return ((X509CertImpl)cert).getEncodedInternal();
        } else {
            return cert.getEncoded();
        }
    }
170860
public static function convertToProtobufAttributeList($encryptedData, $wrappedReceiptKey, $pem)
    {
        $decryptedCipherText = self::decryptCipherText(
            $encryptedData,
            $wrappedReceiptKey,
            $pem
        );

        $attributeList = new \Attrpubapi\AttributeList();
        $attributeList->mergeFromString($decryptedCipherText);

        return $attributeList;
    }
356523
protected function decrypt($encryptedData)
    {
        try {
            if ($this->encryptionKey instanceof Key) {
                return Crypto::decrypt($encryptedData, $this->encryptionKey);
            }

            return Crypto::decryptWithPassword($encryptedData, $this->encryptionKey);
        } catch (Exception $e) {
            throw new LogicException($e->getMessage(), null, $e);
        }
    }
128111
public function decode($responseData)
    {
        switch ($this->format) {
            case 'json':
                return $this->jsonDecode($responseData);
            case 'xml':
                return $this->xmlDecode($responseData);
            default:
                return false;
        }
    }
163866
protected function verifySignatureWithCertificate($certPath, $data, $signature)
    {
        $file = @fopen($certPath, "r");
        if ($file === false) {
            throw new Exception('Could not open certificate file. ');
        }
        $fileSize = filesize($certPath);

        $certificate = fread($file, $fileSize);
        fclose($file);

        $publicKey = openssl_pkey_get_public($certificate);

        $isVerified = openssl_verify($data, $signature, $publicKey);
        openssl_free_key($publicKey);

        if ($isVerified === 0) {
            throw new Exception('Incorrect signature');
        } elseif ($isVerified === -1) {
            throw new Exception('Could not verify signature');
        }

        return $isVerified;
    }
980921
public function decrypt($data){
        $data = base64_decode($data);
        $maxlength = $this->getMaxDecryptBlockSize($this->privateKey);
        $output='';
        while(strlen($data)){
            $input = substr($data, 0, $maxlength);
            $data = substr($data, $maxlength);
            openssl_private_decrypt($input, $out, $this->privateKey);
            $output .= $out;
        }
        return $output;
    }