php8.5
Home/ Manual/ phar / PharData/ PharData::setSignatureAlgorithm

PharData::setSignatureAlgorithm

PHP function Edit on GitHub ✎

Set the signature algorithm for a phar and apply it

Description

PharData::setSignatureAlgorithm(int $algo, string|null $privateKey = null): void

Write

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.

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
<?php
$p = new PharData('archive.tar');
$private = openssl_get_privatekey(file_get_contents('private.pem'));
$pkey = '';
openssl_pkey_export($private, $pkey);
$p->setSignatureAlgorithm(Phar::OPENSSL, $pkey);
?>
        

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

Return Values

Void

Errors/Exceptions

Throws UnexpectedValueException for many errors, BadMethodCallException if called for a zip- or a tar-based phar archive, and a PharException if any problems occur flushing changes to disk.

Changelog

VersionDescription
8.0.0privateKey is now nullable.

See Also

Source: reference/phar/PharData/setSignatureAlgorithm.xml · from the official PHP manual (php/doc-en)