3 namespace pharext\Openssl
;
8 * OpenSSL pkey resource
16 * @param string $password
19 function __construct($file, $password) {
20 $this->key
= openssl_pkey_get_private("file://$file", $password);
21 if (!is_resource($this->key
)) {
22 throw new \
Exception("Could not load private key");
28 * @param \Phar $package
30 function sign(\Phar
$package) {
31 $package->setSignatureAlgorithm(\Phar
::OPENSSL
, $this->key
);
35 * Export the public key to a file
39 function exportPublicKey($file) {
40 if (!file_put_contents("$file.tmp", openssl_pkey_get_details($this->key
)["key"])
41 ||
!rename("$file.tmp", $file)
43 throw new \
Exception(error_get_last()["message"]);