/** * Speichert den Schlüssel als PEM. * * @param string $filename * @param string $password * @param array $config */ public function exportToFile(string $filename, string $password = NULL, array $config = []) { $status = openssl_pkey_export_to_file($this->getHandle(), $filename, $password, $config); if (!$status) { throw new RuntimeException(OpenSSL::getLastError()); } }
/** * @param mixed $publicKey */ public function load($publicKey) { parent::load($publicKey); if ($publicKey instanceof File) { $publicKey = $publicKey->getContent(); } if ($publicKey instanceof SplFileInfo) { $publicKey = file_get_contents($publicKey); } if (is_string($publicKey)) { $handle = openssl_pkey_get_public($publicKey); if (!$handle) { throw new RuntimeException(OpenSSL::getLastError()); } $this->setHandle($handle); } }
/** * @param string $mime * @param $chain * * @return bool */ public function verify(string $mime, $chain) : bool { $inputFileName = new TempFile('smime_signed_'); $inputFileName->setContent($mime); $status = openssl_pkcs7_verify($inputFileName, $this->getFlags(), '/dev/null', [], $chain); if (!is_bool($status)) { throw new RuntimeException(OpenSSL::getLastError()); } return $status; }
/** * @param string $fileName * @param string $password * * @throws RuntimeException */ public function exportToFile(string $fileName, string $password = NULL) { $options = []; if ($this->hasChain()) { $options['extracerts'] = $this->getChain(); } $status = openssl_pkcs12_export_to_file($this->getCertificate(), $fileName, $this->getPrivateKey(), $password, $options); if (!$status) { throw new RuntimeException(OpenSSL::getLastError()); } }
/** * @param string $algorithm * * @return Hash */ public function getFingerprint(string $algorithm = 'SHA1') : Hash { $value = openssl_x509_fingerprint($this->getHandle(), $algorithm, TRUE); if (!$value) { throw new RuntimeException(OpenSSL::getLastError()); } $hash = new Hash($algorithm); $hash->setValue($value); return $hash; }