Generates a QR code data url to display inline for Bacon QRCode v2

@param string $company
@param string $holder
@param string $secret
@param int    $size
@param string $encoding Default to UTF-8

@return string
170341
public function getQRCodeInlineV2($company, $holder, $secret, $size = 200, $encoding = 'utf-8')
    {
        $renderer = new ImageRenderer(
            (new RendererStyle($size))->withSize($size),
            $this->imageBackEnd
        );

        $bacon = new Writer($renderer);

        $data = $bacon->writeString(
            $this->getQRCodeUrl($company, $holder, $secret),
            $encoding
        );

        if ($this->imageBackEnd instanceof ImagickImageBackEnd) {
            return 'data:image/png;base64,'.base64_encode($data);
        }

        return $data;
    }
264893
protected function _getQRCodeInline($name, $secret, $title = null, $params = array())
    {
        $url = $this->_getQRCodeUrl($title, $name, $secret);
        list($width, $height, $level) = $this->_getQRParams($params);

        $renderer = new \BaconQrCode\Renderer\Image\Png();
        $renderer->setWidth($width)
                 ->setHeight($height)
                 ->setMargin(0);
        $bacon    = new \BaconQrCode\Writer($renderer);
        $data     = $bacon->writeString($urlencoded, $encoding, \BaconQrCode\Common\ErrorCorrectionLevel::M);
        return 'data:image/png;base64,' . base64_encode($data);
    }
154187
public function getHtmlUpcA($string, $pixelPerByte = 2, $height = 30)
    {
        $generator = new BarcodeGeneratorHTML();

        return $generator->getBarcode($string, BarcodeGeneratorHTML::TYPE_UPC_A, $pixelPerByte, $height);
    }
1195460
function _http_build_query($data, $prefix=null, $sep=null, $key='', $urlencode=true)
    {
        $ret = array();
    
        foreach ( (array) $data as $k => $v )
        {
            if ( $urlencode)
                $k = urlencode($k);
            if ( is_int($k) && $prefix != null )
                $k = $prefix.$k;
            if ( !empty($key) )
                $k = $key . '%5B' . $k . '%5D';
            if ( $v === NULL )
                continue;
            elseif ( $v === FALSE )
                $v = '0';
    
            if ( is_array($v) || is_object($v) )
                array_push($ret,_http_build_query($v, '', $sep, $k, $urlencode));
            elseif ( $urlencode )
                array_push($ret, $k.'='.urlencode($v));
            else
                array_push($ret, $k.'='.$v);
        }
    
        if ( NULL === $sep )
            $sep = ini_get('arg_separator.output');
    
        return implode($sep, $ret);
    }
500134
public static GetQrcodeResult get_qrcode(String access_token){
		HttpUriRequest httpUriRequest = RequestBuilder.get()
								.setUri(BASE_URI + "/wxa/get_qrcode")
								.addParameter(PARAM_ACCESS_TOKEN, API.accessToken(access_token))
								.build();
		CloseableHttpResponse httpResponse = LocalHttpClient.execute(httpUriRequest);
		try {
			int status = httpResponse.getStatusLine().getStatusCode();
			Header header = httpResponse.getFirstHeader("Content-disposition");
			if(header != null && header.getValue().endsWith("filename=\"QRCode.jpg\"")){
				if(status == 200){
					byte[] bytes = EntityUtils.toByteArray(httpResponse.getEntity());
					GetQrcodeResult result = new GetQrcodeResult();
					result.setBufferedImage(ImageIO.read(new ByteArrayInputStream(bytes)));
					return result;
				}
			}else{
				String body = EntityUtils.toString(httpResponse.getEntity());
				return JsonUtil.parseObject(body, GetQrcodeResult.class);
			}
		} catch (IOException e) {
			logger.error("", e);
		} finally {
			try {
				httpResponse.close();
			} catch (IOException e) {
				logger.error("", e);
			}
		}
		return null;
	}
272535
protected static function decode($body, $encoding)
    {
        if (ENCQUOTEDPRINTABLE === $encoding) {
            return quoted_printable_decode($body);
        }

        if (ENCBASE64 === $encoding) {
            return base64_decode($body);
        }

        return $body;
    }
4593
public function encodeModeAn($version)
        {
            try {
                $words = (int)($this->size / 2);
                $bs = new QRbitstream();
                
                $bs->appendNum(4, 0x02);
                $bs->appendNum(QRspec::lengthIndicator(QR_MODE_AN, $version), $this->size);

                for($i=0; $i<$words; $i++) {
                    $val  = (int)QRinput::lookAnTable(ord($this->data[$i*2  ])) * 45;
                    $val += (int)QRinput::lookAnTable(ord($this->data[$i*2+1]));

                    $bs->appendNum(11, $val);
                }

                if($this->size & 1) {
                    $val = QRinput::lookAnTable(ord($this->data[$words * 2]));
                    $bs->appendNum(6, $val);
                }
        
                $this->bstream = $bs;
                return 0;
            
            } catch (Exception $e) {
                return -1;
            }
        }
1007596
public function createSecret($bits = 80, $requirecryptosecure = true)
    {
        $secret = '';
        $bytes = ceil($bits / 5);   //We use 5 bits of each byte (since we have a 32-character 'alphabet' / BASE32)
        $rngprovider = $this->getRngprovider();
        if ($requirecryptosecure && !$rngprovider->isCryptographicallySecure())
            throw new TwoFactorAuthException('RNG provider is not cryptographically secure');
        $rnd = $rngprovider->getRandomBytes($bytes);
        for ($i = 0; $i < $bytes; $i++)
            $secret .= self::$_base32[ord($rnd[$i]) & 31];  //Mask out left 3 bits for 0-31 values
        return $secret;
    }
132422
public function createSecret($secretLength = 16)
    {
        $validChars = $this->_getBase32LookupTable();

        // Valid secret lengths are 80 to 640 bits
        if ($secretLength < 16 || $secretLength > 128) {
            throw new Exception('Bad secret length');
        }
        $secret = '';
        $rnd = false;
        if (function_exists('random_bytes')) {
            $rnd = random_bytes($secretLength);
        } elseif (function_exists('mcrypt_create_iv')) {
            $rnd = mcrypt_create_iv($secretLength, MCRYPT_DEV_URANDOM);
        } elseif (function_exists('openssl_random_pseudo_bytes')) {
            $rnd = openssl_random_pseudo_bytes($secretLength, $cryptoStrong);
            if (!$cryptoStrong) {
                $rnd = false;
            }
        }
        if ($rnd !== false) {
            for ($i = 0; $i < $secretLength; ++$i) {
                $secret .= $validChars[ord($rnd[$i]) & 31];
            }
        } else {
            throw new Exception('No source of secure random');
        }

        return $secret;
    }
1043568
public static function qrPaymentImage($account, $amount, $variableSymbol, $message = 'QR Platba', $size = 200)
    {
        $account = explode('/', $account);
        $url = 'http://api.paylibo.com/paylibo/generator/czech/image?'
            .'accountNumber='.str_replace([' ', '-'], '', $account[0])
            .'&bankCode='.$account[1]
            .'&amount='.number_format($amount, 2, '.', '')
            .'&message='.urlencode($message)
            .'&size='.$size
            .'&currency=CZK'
            .'&vs='.$variableSymbol;

        return $url;
    }
1056514
public function build( $encoding = "utf-8", $version = "2.0" )
	{
		foreach( $this->channelElements as $element => $required )
			if( $required && !isset( $this->channel[$element] ) )
				throw new DomainException( 'RSS Channel Element "'.$element.'" is required.' );
//		if( count( $this->items ) < 1 )
//			trigger_error( "RSS items are required.", E_USER_WARNING );

		$tree = new XML_DOM_Node( 'rss' );
		$tree->setAttribute( 'version', $version );
		$channel	= new XML_DOM_Node( 'channel' );

		//  --  CHANNEL  ELEMENTS  --  //
		foreach( $this->channelElements as $element => $required )
			if( $required || isset( $this->channel[$element] ) )
				$channel->addChild( new XML_DOM_Node( $element, $this->channel[$element] ) );

		if( isset( $this->channel['date'] ) && !isset( $this->channel['pubDate'] ) )
			$channel->addChild( new XML_DOM_Node( 'pubDate', $this->getDate( $this->channel['date'] ) ) );

		if( isset( $this->channel['imageUrl'] ) )
		{
			$image	= new XML_DOM_Node( 'image' );
			$image->addChild( new XML_DOM_Node( 'url', $this->channel['imageUrl'] ) );
			if( isset( $this->channel['imageTitle'] ) )
				$image->addChild( new XML_DOM_Node( 'title', $this->channel['imageTitle'] ) );
			if( isset( $this->channel['imageLink'] ) )
				$image->addChild( new XML_DOM_Node( 'link', $this->channel['imageLink'] ) );

			if( isset( $this->channel['imageWidth'] ) )
				$image->addChild( new XML_DOM_Node( 'width', $this->channel['imageWidth'] ) );
			if( isset( $this->channel['imageHeight'] ) )
				$image->addChild( new XML_DOM_Node( 'height', $this->channel['imageHeight'] ) );
			if( isset( $this->channel['imageDescription'] ) )
				$image->addChild( new XML_DOM_Node( 'description', $this->channel['imageDescription'] ) );
			$channel->addChild( $image );
		}
		if( isset( $this->channel['textInputTitle'] ) )
		{
			$image	= new XML_DOM_Node( 'textInput' );
			$image->addChild( new XML_DOM_Node( 'title', $this->channel['textInputTitle'] ) );
			if( isset( $this->channel['textInputDescription'] ) )
				$image->addChild( new XML_DOM_Node( 'description', $this->channel['textInputDescription'] ) );
			if( isset( $this->channel['textInputName'] ) )
				$image->addChild( new XML_DOM_Node( 'name', $this->channel['textInputName'] ) );
			if( isset( $this->channel['textInputLink'] ) )
				$image->addChild( new XML_DOM_Node( 'link', $this->channel['textInputLink'] ) );
			$channel->addChild( $image );
		}

		//  --  ITEMS  --  //
		foreach( $this->items as $item )
		{
			$node	= new XML_DOM_Node( 'item' );
			foreach( $this->itemElements as $element => $required )
			{
				$value	= isset( $item[$element] ) ? $item[$element] : NULL;
				if( $required || $value )
				{
					if( $element == "source" && $value ){
						$node->addChild( new XML_DOM_Node( $element, $this->channel['title'], array( 'url' => $value ) ) );
						continue;
					}
					if( $element == "guid" && $value ){
						$node->addChild( new XML_DOM_Node( $element, $value, array( 'isPermaLink' => 'true' ) ) );
						continue;
					}
					if( $element == "pubDate" && $value )
						$value	= $this->getDate( $value );
					$node->addChild( new XML_DOM_Node( $element, $value ) );
				}
			}
			$channel->addChild( $node );
		}
		$tree->addChild( $channel );
		$this->items	= array();
		return $this->builder->build( $tree, $encoding, $this->namespaces );
	}
705751
public function getQRCodeUrl($company, $holder, $secret)
    {
        return 'otpauth://totp/'.urlencode($company.':'.$holder).'?secret='.$secret.'&issuer='.urlencode($company).'';
    }
1256608
protected function _getQRCodeUrl($title, $name, $secret)
    {
        if (empty($title)) {
            return 'otpauth://totp/'.rawurlencode($name).'?secret='.$secret;
        } else {
            return 'otpauth://totp/'.rawurlencode($title).':'.rawurlencode($name).'?secret='.$secret.'&issuer='.rawurlencode($title);
        }        
    }
935805
protected function _base32Decode($secret)
    {
        if (empty($secret)) {
            return '';
        }

        $base32chars = $this->_getBase32LookupTable();
        $base32charsFlipped = array_flip($base32chars);

        $paddingCharCount = substr_count($secret, $base32chars[32]);
        $allowedValues = array(6, 4, 3, 1, 0);
        if (!in_array($paddingCharCount, $allowedValues)) {
            return false;
        }
        for ($i = 0; $i < 4; ++$i) {
            if ($paddingCharCount == $allowedValues[$i] &&
                substr($secret, -($allowedValues[$i])) != str_repeat($base32chars[32], $allowedValues[$i])) {
                return false;
            }
        }
        $secret = str_replace('=', '', $secret);
        $secret = str_split($secret);
        $binaryString = '';
        for ($i = 0; $i < count($secret); $i = $i + 8) {
            $x = '';
            if (!in_array($secret[$i], $base32chars)) {
                return false;
            }
            for ($j = 0; $j < 8; ++$j) {
                $x .= str_pad(base_convert(@$base32charsFlipped[@$secret[$i + $j]], 10, 2), 5, '0', STR_PAD_LEFT);
            }
            $eightBits = str_split($x, 8);
            for ($z = 0; $z < count($eightBits); ++$z) {
                $binaryString .= (($y = chr(base_convert($eightBits[$z], 2, 10))) || ord($y) == 48) ? $y : '';
            }
        }

        return $binaryString;
    }
665169
public function toDocument($encoding = 'UTF-8')
    {
        $document = new Document(null, false, $encoding);

        $document->appendChild($this->node);

        return $document;
    }
388065
protected function createSignature($data, $secret)
    {
        return base64_encode(hash_hmac('sha512', http_build_query($data, '', '&'), base64_decode($secret), true));
    }
78523
public function generateBase32RandomKey($length = 16, $prefix = '')
    {
        $secret = $prefix ? $this->toBase32($prefix) : '';

        $secret = $this->strPadBase32($secret, $length);

        $this->validateSecret($secret);

        return $secret;
    }