Пример #1
0
 /**
  * Convert EC public key to PEM.
  *
  * @return PEM
  */
 public function toPEM()
 {
     $curve_oid = CurveParameter::nameToOID($this->curveParameter()->value());
     $x = ECConversion::octetsToNumber($this->XCoordinateParameter()->coordinateOctets());
     $y = ECConversion::octetsToNumber($this->YCoordinateParameter()->coordinateOctets());
     $ec = ECPublicKey::fromCoordinates($x, $y, $curve_oid);
     return $ec->publicKeyInfo()->toPEM();
 }
Пример #2
0
 /**
  * Convert EC private key to PEM.
  *
  * @return PEM
  */
 public function toPEM()
 {
     $curve_oid = CurveParameter::nameToOID($this->curveParameter()->value());
     $x = ECConversion::octetsToNumber($this->XCoordinateParameter()->coordinateOctets());
     $y = ECConversion::octetsToNumber($this->YCoordinateParameter()->coordinateOctets());
     $pubkey = ECPublicKey::fromCoordinates($x, $y, $curve_oid);
     $priv = $this->ECCPrivateKeyParameter()->privateKeyOctets();
     $ec = new ECPrivateKey($priv, $curve_oid, $pubkey->ECPoint());
     return $ec->privateKeyInfo()->toPEM();
 }