Create a public key from a Mdanter Ecc Public Key.

@param PublicKeyInterface $eccKey

@throws InvalidArgumentException When the public key is not the correct length.
13475
public static function createFromEccKey(PublicKeyInterface $eccKey) : self
    {
        $math = EccFactory::getAdapter();
        $pointSerializer = new UncompressedPointSerializer($math);
        $point = $eccKey->getPoint();
        $hex = $pointSerializer->serialize($point);

        $binary = new BinaryString(hex2bin($hex));

        return new self($binary);
    }
737907
public static function seal(
        string $plaintext,
        SealingPublicKey $publicKey
    ): string {
        $ephemeralSecret = SealingSecretKey::generate();
        $sharedSecret = static::keyExchange(
            $ephemeralSecret,
            $publicKey,
            false,
            56
        );
        $ephemeralPublicKey = $ephemeralSecret->getPublickey()->getString(true);
        $sharedKey = \ParagonIE_Sodium_Core_Util::substr($sharedSecret, 0, 32);
        $nonce = \ParagonIE_Sodium_Core_Util::substr($sharedSecret, 32, 24);
        try {
            \ParagonIE_Sodium_Compat::memzero($sharedSecret);
        } catch (\Throwable $ex) {
        }

        return $ephemeralPublicKey. \ParagonIE_Sodium_Compat::crypto_aead_xchacha20poly1305_ietf_encrypt(
            $plaintext,
            $ephemeralPublicKey,
            $nonce,
            $sharedKey
        );
    }
9454
public static function fromPrivateKey(EccPrivateKey $privateKey, AbstractNetwork $network = null): string
    {
        $digest = Hash::ripemd160($privateKey->getPublicKey()->getBuffer());

        return (new PayToPubKeyHashAddress($digest))->getAddress($network);
    }
1075358
protected function getIdentifier(\fpoirotte\Pssht\PublicKeyInterface $key)
    {
        $encoder = new \fpoirotte\Pssht\Wire\Encoder();
        $key->serialize($encoder);
        return $encoder->getBuffer()->get(0);
    }
501657
protected static function rsaEncrypt($plaintext, PublicKey $rsaPublicKey)
    {
        $rsa = self::getRsa(RSA::ENCRYPTION_OAEP);

        $return = $rsa->loadKey($rsaPublicKey->getKey());
        if ($return === false) {
            throw new InvalidKeyException('Ecryption failed due to invalid key');
        }

        return $rsa->encrypt($plaintext);
    }
1029317
private PublicKey createPublicKey(String cert) {
        try {
            CertificateFactory fact = CertificateFactory.getInstance("X.509");
            InputStream stream = new ByteArrayInputStream(cert.getBytes(Charset.forName("UTF-8")));
            X509Certificate cer = (X509Certificate) fact.generateCertificate(stream);
            validateCertificate(cer);
            return cer.getPublicKey();
        } catch (SdkBaseException e) {
            throw e;
        } catch (Exception e) {
            throw new SdkClientException("Could not create public key from certificate", e);
        }
    }
82704
public static function extendedKeyBase58Decode($key)
    {
        // The base58-decoded extended key must consist of a serialized payload
        // plus an additional 4 bytes for the checksum.
        $decoded = static::base58()->decode($key);

        if (strlen($decoded) !== 82) {
            throw new \InvalidArgumentException('Wrong key length.');
        }

        // Split the payload and checksum up and ensure the checksum matches.
        $payload = substr($decoded, 0, 78);
        $expected = substr($decoded, -4);

        // Verify checksum of provided key
        $network = NetworkFactory::fromExtendedKeyVersion(substr($payload, 0, 4));
        $checksum = substr($network->base58Checksum($payload), 0, 4);

        if ($expected !== $checksum) {
            throw new \InvalidArgumentException('Wrong checksum on encoding extended key!');
        }

        return $decoded;
    }
444088
public function make($key)
    {
        // Check if set
        if (!isset($this->keys[$key])) {
            throw new \InvalidArgumentException('Identifier "'. $key .'" is not defined.');
        }

        // Check if it is a simple value (string, int etc) that
        // should be returned
        if (
            !is_object($this->raw[$key])
            || !method_exists($this->raw[$key], '__invoke')
        ) {
            return $this->raw[$key];
        }

        if ($this->types[$key] === self::TYPE_SINGLETON) {
            if (isset($this->resolved[$key])) {
                return $this->resolved[$key];
            }

            $this->locked[$key] = true;
            return $this->resolved[$key] = $this->raw[$key]($this);
        }

        // Return multiton
        return $this->raw[$key]($this);
    }
1006334
public function normalizeKey($key)
	{
		$normalizedKey = filter_var(
			(preg_match('(^-\\d+$)D', $key)) ? count($this->items) + $key : $key,
			FILTER_VALIDATE_INT,
			[
				'options' => [
					'min_range' => 0,
					'max_range' => count($this->items)
				]
			]
		);

		if ($normalizedKey === false)
		{
			throw new InvalidArgumentException("Invalid offset '" . $key . "'");
		}

		return $normalizedKey;
	}
771498
public function setInitKey($key)
    {
        if (preg_match('/^['.implode('', array_keys($this->getLookup())).']+$/', $key) == false) {
            throw new \InvalidArgumentException('Invalid base32 hash!');
        }
        $this->initKey = $key;
        return $this;
    }
437323
private function createContext($userPublicKey)
    {
        $label = 'P-256';
        // The two length fields are encoded as a two octet unsigned integer in network byte order.
        $recipientPublicLength = chr(0).chr(strlen($userPublicKey));
        $senderPublicLength = chr(0).chr(strlen($this->publicKeyContent));

        return $label.chr(0).$recipientPublicLength.$userPublicKey.$senderPublicLength.$this->publicKeyContent;
    }
920489
public static function sign($hexDataToSign, $privateKey)
    {
        if (is_string($privateKey)) {
            $privateKey = PrivateKeyManipulator::importPrivateKey($privateKey);
        }

        // Convert hex data to buffer
        $data = Buffer::hex($hexDataToSign);

        /** @var EcAdapterInterface $ecAdapter */
        $ecAdapter = Bitcoin::getEcAdapter();

        // Deterministic digital signature generation
        $k = new Rfc6979($ecAdapter, $privateKey, $data, 'sha256');

        $sig = $ecAdapter->sign($data, $privateKey, $k);

        // DEBUG
        //echo "hexDataToSign: <br/>";
        //var_dump($hexDataToSign);
        //echo "sig: <br/>";
        //var_dump($sig->getHex());

        return $sig->getHex();
    }
788611
private function getGenerator(JWKInterface $key)
    {
        $crv = $key->get('crv');

        switch ($crv) {
            case 'P-256':
                return EccFactory::getNistCurves()->generator256();
            case 'P-384':
                return EccFactory::getNistCurves()->generator384();
            case 'P-521':
                return EccFactory::getNistCurves()->generator521();
            default:
                throw new \InvalidArgumentException(sprintf('The curve "%s" is not supported', $crv));
        }
    }
149370
public function createCertificate($name, $certificate, $privateKey, $intermediates)
    {
        $this->notAvailableInVersions(1);

        return $this->send('create_certificate', $name, $certificate, $privateKey, $intermediates);
    }
78138
public function create($name, $publicKey)
    {
        $key = $this->adapter->post(sprintf('%s/account/keys', $this->endpoint), ['name' => $name, 'public_key' => $publicKey]);

        $key = json_decode($key);

        return new KeyEntity($key->ssh_key);
    }
750780
private function getKey($key)
    {
        if (!isset($this->cache[$key])) {
            if (!isset($this->mappings[$key])) {
                list($type, $name) = explode('.', $key);
                throw new InvalidArgumentException("No {$type} visitor has been mapped for {$name}");
            }
            $this->cache[$key] = new $this->mappings[$key];
        }

        return $this->cache[$key];
    }
780564
public function Generate($pubkey)
    {
        if (empty($pubkey) === true) {
            throw new \Exception('Missing or invalid public key parameter for Sin::Generate.');
        }

        /* take the sha256 hash of the public key in binary form and returning binary */
        $this->rawHashes['step1'] = hash('sha256', $this->binConv($pubkey), true);

        /* take the ripemd160 hash of the sha256 hash in binary form returning hex */
        $this->rawHashes['step2'] = hash('ripemd160', $this->rawHashes['step1']);

        /* prepend the hex SINversion and hex SINtype to the hex form of the ripemd160 hash */
        $this->rawHashes['step3'] = $this->SINversion . $this->SINtype . $this->rawHashes['step2'];

        /*
         * convert the appended hex string back to binary and double sha256 hash it leaving
         * it in binary both times
         */
        $this->rawHashes['step4'] = hash('sha256', hash('sha256', $this->binConv($this->rawHashes['step3']), true), true);

        /* convert it back to hex and take the first 4 hex bytes */
        $this->rawHashes['step5'] = substr(bin2hex($this->rawHashes['step4']), 0, 8);

        /* append the first 4 bytes to the fully appended string in step 3 */
        $this->rawHashes['step6'] = $this->rawHashes['step3'] . $this->rawHashes['step5'];

        /* finally base58 encode it */
        $this->encoded = $this->encodeBase58($this->rawHashes['step6']);

        if (empty($this->encoded) === true) {
            throw new \Exception('Failed to generate valid SIN value. Empty or NULL value was obtained.');
        }

        return $this->encoded;
    }