XBRL-Signer.php
private function generate_signature( $content, $private_key_pem, $signature_alg = "SHA256" )
	{
		// The function openssl_pkey_get_private always works with URLs so if necessary convert
		// the $private_key_pem variable to a URL using a 'file' scheme.  If there is no scheme
		// or the scheme is a letter A-Z then a local path is being used and needs converting.
		$parts = parse_url( $private_key_pem );
		if ( ( ! isset( $parts['scheme'] ) || preg_match( "/^[A-Z]$/", $parts['scheme'] ) ) && ! isset( $parts['host'] ) )
		{
			$private_key_pem = "file://";
			if ( isset( $parts['scheme'] ) ) $private_key_pem .= $parts['scheme'] . ":";
			$private_key_pem .= $parts['path'];
		}

		$private_key = openssl_pkey_get_private( $private_key_pem );

		if ( $private_key === false )
		{
			$message = "Unable to create a key id from the private key resource $pem\n" . openssl_error_string();
			throw new \Exception( $message );
		}

		$signature = null;

		$result = openssl_sign( $content, $signature, $private_key, $signature_alg );
		if ( ! $result )
		{
			$message = "Error to signing: " . openssl_error_string();
		}

		openssl_free_key( $private_key );

		if ( ! $result )
			throw new \Exception( $message );

			return base64_encode( $signature );
	}
private function generate_signature( $content, $private_key_pem, $signature_alg = "SHA256" )
	{
		// The function openssl_pkey_get_private always works with URLs so if necessary convert
		// the $private_key_pem variable to a URL using a 'file' scheme.  If there is no scheme
		// or the scheme is a letter A-Z then a local path is being used and needs converting.
		$parts = parse_url( $private_key_pem );
		if ( ( ! isset( $parts['scheme'] ) || preg_match( "/^[A-Z]$/", $parts['scheme'] ) ) && ! isset( $parts['host'] ) )
		{
			$private_key_pem = "file://";
			if ( isset( $parts['scheme'] ) ) $private_key_pem .= $parts['scheme'] . ":";
			$private_key_pem .= $parts['path'];
		}

		$private_key = openssl_pkey_get_private( $private_key_pem );

		if ( $private_key === false )
		{
			$message = "Unable to create a key id from the private key resource $pem\n" . openssl_error_string();
			throw new \Exception( $message );
		}

		$signature = null;

		$result = openssl_sign( $content, $signature, $private_key, $signature_alg );
		if ( ! $result )
		{
			$message = "Error to signing: " . openssl_error_string();
		}

		openssl_free_key( $private_key );

		if ( ! $result )
			throw new \Exception( $message );

			return base64_encode( $signature );
	}
private function generate_signature ( $ content , $ private_key_pem , $ signature_alg = "SHA256" ) { // The function openssl_pkey_get_private always works with URLs so if necessary convert
 // the $private_key_pem variable to a URL using a 'file' scheme.  If there is no scheme
 // or the scheme is a letter A-Z then a local path is being used and needs converting.
 $ parts = parse_url ( $ private_key_pem ) ; if ( ( ! isset ( $ parts [ 'scheme' ] ) || preg_match ( "/^[A-Z]$/" , $ parts [ 'scheme' ] ) ) && ! isset ( $ parts [ 'host' ] ) ) { $ private_key_pem = "file://" ; if ( isset ( $ parts [ 'scheme' ] ) ) $ private_key_pem .= $ parts [ 'scheme' ] . ":" ; $ private_key_pem .= $ parts [ 'path' ] ; } $ private_key = openssl_pkey_get_private ( $ private_key_pem ) ; if ( $ private_key === false ) { $ message = "Unable to create a key id from the private key resource $pem\n" . openssl_error_string ( ) ; throw new \ Exception ( $ message ) ; } $ signature = null ; $ result = openssl_sign ( $ content , $ signature , $ private_key , $ signature_alg ) ; if ( ! $ result ) { $ message = "Error to signing: " . openssl_error_string ( ) ; } openssl_free_key ( $ private_key ) ; if ( ! $ result ) throw new \ Exception ( $ message ) ; return base64_encode ( $ signature ) ; }
Sign content to produce a signature using a private key
@param string $content  The content to be signed
@param string $private_key_pem The private key in PEM format.  Can be a string containing the key or a path to a file containing the key.
@param string $signature_alg The name the hash algorithm to use (Default: SHA256)
@throws \Exception An exception will be thrown if the private key cannnot be opened or used or if there is a problem signing.
@return string The signature
Sign content to produce a signature using a private key