/**
  * @param string $data
  * {@inheritDoc}
  * @see \Mdanter\Ecc\Serializer\PrivateKeySerializerInterface::parse()
  * @throws \FG\ASN1\Exception\ParserException
  */
 public function parse($data)
 {
     $asnObject = Object::fromBinary($data);
     if (!$asnObject instanceof Sequence || $asnObject->getNumberofChildren() !== 4) {
         throw new \RuntimeException('Invalid data.');
     }
     $children = $asnObject->getChildren();
     $version = $children[0];
     if ($version->getContent() != 1) {
         throw new \RuntimeException('Invalid data: only version 1 (RFC5915) keys are supported.');
     }
     $key = $this->adapter->hexDec($children[1]->getContent());
     $oid = $children[2]->getContent();
     $generator = CurveOidMapper::getGeneratorFromOid($oid);
     return $generator->getPrivateKeyFrom($key);
 }
Esempio n. 2
0
 public function parse($binaryData)
 {
     $asnObject = Object::fromBinary($binaryData);
     if (!$asnObject instanceof Sequence || $asnObject->getNumberofChildren() != 2) {
         throw new \RuntimeException('Invalid data.');
     }
     $children = $asnObject->getChildren();
     $oid = $children[0]->getChildren()[0];
     $curveOid = $children[0]->getChildren()[1];
     $encodedKey = $children[1];
     if ($oid->getContent() !== DerPublicKeySerializer::X509_ECDSA_OID) {
         throw new \RuntimeException('Invalid data: non X509 data.');
     }
     $generator = CurveOidMapper::getGeneratorFromOid($curveOid);
     return $this->parseKey($generator, $encodedKey->getContent());
 }