PHP: Phar::setSignatureAlgorithm - Manual (original) (raw)

(PHP 5 >= 5.3.0, PHP 7, PHP 8, PECL phar >= 1.1.0)

Phar::setSignatureAlgorithm — Set the signature algorithm for a phar and apply it

Description

public Phar::setSignatureAlgorithm(int $algo, ?string $privateKey = [null](reserved.constants.php#constant.null)): void

Note:

This method requires the php.ini setting phar.readonly to be set to 0 in order to work for Pharobjects. Otherwise, a PharException will be thrown.

set the signature algorithm for a phar and apply it. The signature algorithm must be one of Phar::MD5,Phar::SHA1, Phar::SHA256,Phar::SHA512, or Phar::OPENSSL.

Note that all executable phar archives have a signature created automatically, SHA1 by default. data tar- or zip-based archives (archives created with the PharData class) must have their signature created and set explicitly viaPhar::setSignatureAlgorithm().

Parameters

algo

One of Phar::MD5,Phar::SHA1, Phar::SHA256,Phar::SHA512, or Phar::OPENSSL

privateKey

The contents of an OpenSSL private key, as extracted from a certificate or OpenSSL key file:

<?php $private = openssl_get_privatekey(file_get_contents('private.pem')); $pkey = ''; openssl_pkey_export($private, $pkey); <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>p</mi><mo>−</mo><mo>&gt;</mo><mi>s</mi><mi>e</mi><mi>t</mi><mi>S</mi><mi>i</mi><mi>g</mi><mi>n</mi><mi>a</mi><mi>t</mi><mi>u</mi><mi>r</mi><mi>e</mi><mi>A</mi><mi>l</mi><mi>g</mi><mi>o</mi><mi>r</mi><mi>i</mi><mi>t</mi><mi>h</mi><mi>m</mi><mo stretchy="false">(</mo><mi>P</mi><mi>h</mi><mi>a</mi><mi>r</mi><mo>:</mo><mo>:</mo><mi>O</mi><mi>P</mi><mi>E</mi><mi>N</mi><mi>S</mi><mi>S</mi><mi>L</mi><mo separator="true">,</mo></mrow><annotation encoding="application/x-tex">p-&gt;setSignatureAlgorithm(Phar::OPENSSL, </annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.7778em;vertical-align:-0.1944em;"></span><span class="mord mathnormal">p</span><span class="mord">−</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">&gt;</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal">se</span><span class="mord mathnormal" style="margin-right:0.05764em;">tS</span><span class="mord mathnormal">i</span><span class="mord mathnormal" style="margin-right:0.03588em;">g</span><span class="mord mathnormal">na</span><span class="mord mathnormal">t</span><span class="mord mathnormal">u</span><span class="mord mathnormal">re</span><span class="mord mathnormal">A</span><span class="mord mathnormal" style="margin-right:0.01968em;">l</span><span class="mord mathnormal" style="margin-right:0.03588em;">g</span><span class="mord mathnormal" style="margin-right:0.02778em;">or</span><span class="mord mathnormal">i</span><span class="mord mathnormal">t</span><span class="mord mathnormal">hm</span><span class="mopen">(</span><span class="mord mathnormal" style="margin-right:0.13889em;">P</span><span class="mord mathnormal">ha</span><span class="mord mathnormal" style="margin-right:0.02778em;">r</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">::</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:0.8778em;vertical-align:-0.1944em;"></span><span class="mord mathnormal" style="margin-right:0.05764em;">OPENSS</span><span class="mord mathnormal">L</span><span class="mpunct">,</span></span></span></span>pkey); ?>

See phar introduction for instructions on naming and placement of the public key file.

Return Values

No value is returned.

Changelog

Version Description
8.0.0 privateKey is now nullable.

See Also