Storage/src/EncryptionTrait.php
protected function signString($privateKey, $data, $forceOpenssl = false)
    {
        $signature = '';

        if (class_exists(RSA::class) && !$forceOpenssl) {
            $rsa = new RSA;
            $rsa->loadKey($privateKey);
            $rsa->setSignatureMode(RSA::SIGNATURE_PKCS1);
            $rsa->setHash('sha256');

            $signature = $rsa->sign($data);
        } elseif (extension_loaded('openssl')) {
            openssl_sign($data, $signature, $privateKey, 'sha256WithRSAEncryption');
        } else {
            // @codeCoverageIgnoreStart
            throw new \RuntimeException('OpenSSL is not installed.');
        }
        // @codeCoverageIgnoreEnd

        return $signature;
    }
protected function signString($privateKey, $data, $forceOpenssl = false)
    {
        $signature = '';

        if (class_exists(RSA::class) && !$forceOpenssl) {
            $rsa = new RSA;
            $rsa->loadKey($privateKey);
            $rsa->setSignatureMode(RSA::SIGNATURE_PKCS1);
            $rsa->setHash('sha256');

            $signature = $rsa->sign($data);
        } elseif (extension_loaded('openssl')) {
            openssl_sign($data, $signature, $privateKey, 'sha256WithRSAEncryption');
        } else {
            // @codeCoverageIgnoreStart
            throw new \RuntimeException('OpenSSL is not installed.');
        }
        // @codeCoverageIgnoreEnd

        return $signature;
    }
protected function signString ( $ privateKey , $ data , $ forceOpenssl = false ) { $ signature = '' ; if ( class_exists ( RSA :: class ) && ! $ forceOpenssl ) { $ rsa = new RSA ; $ rsa -> loadKey ( $ privateKey ) ; $ rsa -> setSignatureMode ( RSA :: SIGNATURE_PKCS1 ) ; $ rsa -> setHash ( 'sha256' ) ; $ signature = $ rsa -> sign ( $ data ) ; } elseif ( extension_loaded ( 'openssl' ) ) { openssl_sign ( $ data , $ signature , $ privateKey , 'sha256WithRSAEncryption' ) ; } else { // @codeCoverageIgnoreStart throw new \ RuntimeException ( 'OpenSSL is not installed.' ) ; } // @codeCoverageIgnoreEnd return $ signature ; }
Sign a string using a given private key.

@deprecated Please use the {@see Google\Auth\SignBlobInterface::signBlob()}
and implementations for signing strings.
This method will be removed in a future release.

@param string $privateKey The private key to use to sign the data.
@param string $data The data to sign.
@param bool $forceOpenssl If true, OpenSSL will be used regardless of
whether phpseclib is available. **Defaults to** `false`.
@return string The signature
Sign a string using a given private key .