src/Widop/GoogleAnalytics/Client.php
protected function generateSignature($jsonWebToken)
    {
        if (!function_exists('openssl_x509_read')) {
            throw GoogleAnalyticsException::invalidOpenSslExtension();
        }

        $certificate = file_get_contents($this->privateKeyFile);

        $certificates = array();
        if (!openssl_pkcs12_read($certificate, $certificates, 'notasecret')) {
            throw GoogleAnalyticsException::invalidPKCS12File();
        }

        if (!isset($certificates['pkey']) || !$certificates['pkey']) {
            throw GoogleAnalyticsException::invalidPKCS12Format();
        }

        $ressource = openssl_pkey_get_private($certificates['pkey']);

        if (!$ressource) {
            throw GoogleAnalyticsException::invalidPKCS12PKey();
        }

        $signature = null;
        if (!openssl_sign($jsonWebToken, $signature, $ressource, 'sha256')) {
            throw GoogleAnalyticsException::invalidPKCS12Signature();
        }

        openssl_pkey_free($ressource);

        return $signature;
    }
protected function generateSignature($jsonWebToken)
    {
        if (!function_exists('openssl_x509_read')) {
            throw GoogleAnalyticsException::invalidOpenSslExtension();
        }

        $certificate = file_get_contents($this->privateKeyFile);

        $certificates = array();
        if (!openssl_pkcs12_read($certificate, $certificates, 'notasecret')) {
            throw GoogleAnalyticsException::invalidPKCS12File();
        }

        if (!isset($certificates['pkey']) || !$certificates['pkey']) {
            throw GoogleAnalyticsException::invalidPKCS12Format();
        }

        $ressource = openssl_pkey_get_private($certificates['pkey']);

        if (!$ressource) {
            throw GoogleAnalyticsException::invalidPKCS12PKey();
        }

        $signature = null;
        if (!openssl_sign($jsonWebToken, $signature, $ressource, 'sha256')) {
            throw GoogleAnalyticsException::invalidPKCS12Signature();
        }

        openssl_pkey_free($ressource);

        return $signature;
    }
protected function generateSignature ( $ jsonWebToken ) { if ( ! function_exists ( 'openssl_x509_read' ) ) { throw GoogleAnalyticsException :: invalidOpenSslExtension ( ) ; } $ certificate = file_get_contents ( $ this -> privateKeyFile ) ; $ certificates = array ( ) ; if ( ! openssl_pkcs12_read ( $ certificate , $ certificates , 'notasecret' ) ) { throw GoogleAnalyticsException :: invalidPKCS12File ( ) ; } if ( ! isset ( $ certificates [ 'pkey' ] ) || ! $ certificates [ 'pkey' ] ) { throw GoogleAnalyticsException :: invalidPKCS12Format ( ) ; } $ ressource = openssl_pkey_get_private ( $ certificates [ 'pkey' ] ) ; if ( ! $ ressource ) { throw GoogleAnalyticsException :: invalidPKCS12PKey ( ) ; } $ signature = null ; if ( ! openssl_sign ( $ jsonWebToken , $ signature , $ ressource , 'sha256' ) ) { throw GoogleAnalyticsException :: invalidPKCS12Signature ( ) ; } openssl_pkey_free ( $ ressource ) ; return $ signature ; }
Generates the JWT signature according to the private key file and the JWT content.

@param string $jsonWebToken The JWT content.

@throws \Widop\GoogleAnalytics\Exception\GoogleAnalyticsException If an error occured when generating the signature.

@return string The JWT signature.
Generates the JWT signature according to the private key file and the JWT content .