As a note, the docs don't show the (optional) second parameter nor mention the existence of the Phar::OPENSSL class constant also available for use with this method.
To sign a phar with OpenSSL, for example...
<?php
$phar = new Phar('somephar.phar');
// ... add your files and such
$phar->setSignatureAlgorithm(Phar::OPENSSL, file_get_contents('private_key_here.pem'));
// ... do whatever else you want afterwards here ...
?>
Hope this proves useful to someone.
Phar::setSignatureAlgorithm
(PHP >= 5.3.0, PECL phar >= 1.1.0)
Phar::setSignatureAlgorithm — Establecer el algoritmo de firma para un phar y aplicarlo
Descripción
$sigtype
)Nota:
Este método requiere que la opción de php.ini phar.readonly esté establecida a 0 para que trabaje con objetos Phar. De otra manera, se lanzará una excepción de tipo PharException.
Establece el algoritmo de firma para un phar y lo aplica. El algoritmo de firma debe ser una de las constantes Phar::MD5, Phar::SHA1, Phar::SHA256, Phar::SHA512, o Phar::OPENSSL. (PGP aún no está soportado y se recurre a SHA-1).
Parámetros
-
sigtype -
Una de las constantes Phar::MD5, Phar::SHA1, Phar::SHA256, Phar::SHA512, or Phar::PGP
Valores devueltos
No devuelve ningún valor.
Errores/Excepciones
Lanza una excepción de tipo UnexpectedValueException para muchos errores, una excepción de tipo BadMethodCallException si se llamó para un archivo basao en zip o en tar, y una excepción de tipo PharException si ocurrió algún problema al volcar los cambios al disco.
Ver también
- Phar::getSupportedSignatures() - Devolver un array con los tipos de firmas soportados
- Phar::getSignature() - Devolver la firma MD5/SHA1/SHA256/SHA512/OpenSSL de un archivo Phar
