コード例 #1
0
ファイル: Parser.php プロジェクト: phpecc/x509
 /**
  * @param string $certificate
  * @return Certificate
  * @throws \Exception
  * @throws \FG\ASN1\Exception\ParserException
  */
 public function parse($certificate)
 {
     $certificate = str_replace(CertificateSerializer::HEADER, '', $certificate);
     $certificate = str_replace(CertificateSerializer::FOOTER, '', $certificate);
     $binary = base64_decode($certificate);
     $asnObject = Object::fromBinary($binary);
     if (!$asnObject instanceof Sequence || $asnObject->getNumberOfChildren() !== 3) {
         throw new \InvalidArgumentException('Invalid data.');
     }
     // Parse Certificate Info
     $children = $asnObject->getChildren();
     if (!$children[0] instanceof Sequence) {
         throw new \InvalidArgumentException('Invalid data: certificate info');
     }
     $info = $this->parseCertificateInfo($children[0]);
     // Parse Signature Algorithm
     $sigSection = $children[1];
     if (!$sigSection instanceof Sequence) {
         throw new \Exception('Invaid sig algo section');
     }
     $sigAlg = $this->parseSigAlg($sigSection);
     // Parse Signature
     if (!$children[2] instanceof BitString) {
         throw new \Exception('Invalid signature');
     }
     $signature = $this->sigSer->parse(hex2bin($children[2]->getContent()));
     return new Certificate($info, $sigAlg, $signature);
 }
コード例 #2
0
ファイル: Formatter.php プロジェクト: phpecc/x509
 /**
  * @param Certificate $cert
  * @return Sequence
  */
 public function getCertificateASN(Certificate $cert)
 {
     return new Sequence($this->getCertInfoASN($cert->getInfo()), new Sequence(SigAlgorithmOidMapper::getSigAlgorithmOid($cert->getSigAlgorithm())), new BitString(bin2hex($this->sigSer->serialize($cert->getSignature()))));
 }
コード例 #3
0
ファイル: CsrSerializer.php プロジェクト: phpecc/x509
 /**
  * @param Csr $csr
  * @return Sequence
  */
 public function getCsrASN(Csr $csr)
 {
     return new Sequence($this->getCertRequestInfoASN($csr->getCurve(), $csr->getPublicKey(), $csr->getSubject()), new Sequence(SigAlgorithmOidMapper::getSigAlgorithmOid($csr->getSigAlgorithm())), new BitString(bin2hex($this->sigSer->serialize($csr->getSignature()))));
 }