static function signString($string, $privateKeyFile, $privateKeyPassword = "") {

		if (!function_exists("openssl_get_privatekey")) {
			throw new CryptoException("OpenSSL extension in PHP is required. Please install or enable it.");
		}

		if (!file_exists($privateKeyFile) or !is_readable($privateKeyFile)) {
			throw new CryptoException("Private key file \"$privateKeyFile\" not found or not readable.");
		}

		$keyAsString = file_get_contents($privateKeyFile);

		$privateKeyId = openssl_get_privatekey($keyAsString, $privateKeyPassword);
		if (!$privateKeyId) {
			throw new CryptoException("Private key could not be loaded from file \"$privateKeyFile\". Please make sure that the file contains valid private key in PEM format.");
		}

		$ok = openssl_sign($string, $signature, $privateKeyId, self::HASH_METHOD);
		if (!$ok) {
			throw new CryptoException("Signing failed.");
		}
		$signature = base64_encode ($signature);
		openssl_free_key ($privateKeyId);

		return $signature;
	}
static function signString($string, $privateKeyFile, $privateKeyPassword = "") {

		if (!function_exists("openssl_get_privatekey")) {
			throw new CryptoException("OpenSSL extension in PHP is required. Please install or enable it.");
		}

		if (!file_exists($privateKeyFile) or !is_readable($privateKeyFile)) {
			throw new CryptoException("Private key file \"$privateKeyFile\" not found or not readable.");
		}

		$keyAsString = file_get_contents($privateKeyFile);

		$privateKeyId = openssl_get_privatekey($keyAsString, $privateKeyPassword);
		if (!$privateKeyId) {
			throw new CryptoException("Private key could not be loaded from file \"$privateKeyFile\". Please make sure that the file contains valid private key in PEM format.");
		}

		$ok = openssl_sign($string, $signature, $privateKeyId, self::HASH_METHOD);
		if (!$ok) {
			throw new CryptoException("Signing failed.");
		}
		$signature = base64_encode ($signature);
		openssl_free_key ($privateKeyId);

		return $signature;
	}
static function signString ( $ string , $ privateKeyFile , $ privateKeyPassword = "" ) { if ( ! function_exists ( "openssl_get_privatekey" ) ) { throw new CryptoException ( "OpenSSL extension in PHP is required. Please install or enable it." ) ; } if ( ! file_exists ( $ privateKeyFile ) or ! is_readable ( $ privateKeyFile ) ) { throw new CryptoException ( "Private key file \"$privateKeyFile\" not found or not readable." ) ; } $ keyAsString = file_get_contents ( $ privateKeyFile ) ; $ privateKeyId = openssl_get_privatekey ( $ keyAsString , $ privateKeyPassword ) ; if ( ! $ privateKeyId ) { throw new CryptoException ( "Private key could not be loaded from file \"$privateKeyFile\". Please make sure that the file contains valid private key in PEM format." ) ; } $ ok = openssl_sign ( $ string , $ signature , $ privateKeyId , self :: HASH_METHOD ) ; if ( ! $ ok ) { throw new CryptoException ( "Signing failed." ) ; } $ signature = base64_encode ( $ signature ) ; openssl_free_key ( $ privateKeyId ) ; return $ signature ; }
Signs a string

@param string $string
@param string $privateKeyFile Path to file with your private key (the .key file from https://iplatebnibrana.csob.cz/keygen/ )
@param string $privateKeyPassword Password to the key, if it was generated with one. Leave empty if you created the key at https://iplatebnibrana.csob.cz/keygen/
@return string Signature encoded with Base64
@throws CryptoException When signing fails or key file path is not valid
Signs a string