Signature::generate

@param array  $segments
@param string $key
@param string $algorithm

@return bool|string
@throws \O2System\Spl\Exceptions\Logic\DomainException
16834
public static function generate(array $segments, $key, $algorithm = 'HS256')
    {
        if (count($segments) == 2) {
            $data = implode('.', $segments);

            if (Algorithm::validate($algorithm)) {
                list($function, $algorithm) = Algorithm::map($algorithm);

                switch ($function) {
                    case 'HMAC':
                        return Hmac::hash($algorithm, $data, $key, true);
                    case 'hash_hmac':
                        return hash_hmac($algorithm, $data, $key, true);
                    case 'openssl':
                        return openssl_sign($data, $signature, $key, $algorithm);
                }
            }
        }

        return false;
    }
112147
public function generateSignature($data, $key = null)
    {
        if ($key === null) {
            $key = $this->getApiKey();
            if ($key === null || empty($key)) {
                throw new \InvalidArgumentException('Invalid API key!');
            }
        }

        $query = http_build_query($data);
        $query = utf8_encode(str_replace('%3A', ':', $query));

        $hash = preg_replace(
            '/\+/', '%2B',
            // base64_encode(hash_hmac('sha1', http_build_query($data), $key, true))
            base64_encode(hash_hmac('sha1', $query, $key, true))
        );
        return $hash;
    }
140804
public function generate($key = '', $config = [], array $query = [])
    {
        $routes = $this->router->getRoutes();
        $queryString = '';
        if (!$key) {
            return $this->protocol . $this->base;
        }
        $routes = $routes->getByOptionKeyValue('id', $key);
        if (!$route = $routes->getFirst()) {
            throw new \Exception("route '$key' cannot be generated");
        }
        $path = ltrim($route->path, '/');
        foreach ($config as $key => $value) {
            $path = str_replace(':' . $key, $value, $path);
        }
        if ($query) {
            $queryString = '?' . http_build_query($query);
        }
        return $this->protocol . $this->base . $path . $queryString;
    }
793990
public static byte[] sign(byte[] text, PrivateKey key, String algorithm) throws SignatureException {
        Signature signature;
        try {
            signature = Signature.getInstance(algorithm);
            signature.initSign(key);
        } catch (GeneralSecurityException e) {
            throw new IllegalArgumentException("cannot initialize signature for algorithm " + algorithm, e);
        }
        signature.update(text);
        return signature.sign();
    }
581566
public static KeyPair generateKeyPair(String algorithm, byte[] seed, AlgorithmParameterSpec param) {
		return generateKeyPair(algorithm, DEFAULT_KEY_SIZE, seed, param);
	}
1105881
public static PublicKey generatePublicKey(String algorithm, KeySpec keySpec) {
		if (null == keySpec) {
			return null;
		}
		algorithm = getAlgorithmAfterWith(algorithm);
		try {
			return getKeyFactory(algorithm).generatePublic(keySpec);
		} catch (Exception e) {
			throw new CryptoException(e);
		}
	}
445154
function _encryption_algorithm_to_crypt_instance($algorithm)
    {
        switch ($algorithm) {
            case '3des-cbc':
                return new TripleDES();
            case '3des-ctr':
                return new TripleDES(Base::MODE_CTR);
            case 'aes256-cbc':
            case 'aes192-cbc':
            case 'aes128-cbc':
                return new Rijndael();
            case 'aes256-ctr':
            case 'aes192-ctr':
            case 'aes128-ctr':
                return new Rijndael(Base::MODE_CTR);
            case 'blowfish-cbc':
                return new Blowfish();
            case 'blowfish-ctr':
                return new Blowfish(Base::MODE_CTR);
            case 'twofish128-cbc':
            case 'twofish192-cbc':
            case 'twofish256-cbc':
            case 'twofish-cbc':
                return new Twofish();
            case 'twofish128-ctr':
            case 'twofish192-ctr':
            case 'twofish256-ctr':
                return new Twofish(Base::MODE_CTR);
            case 'arcfour':
            case 'arcfour128':
            case 'arcfour256':
                return new RC4();
        }
        return null;
    }
83077
private function _sign($data, $key, $algorithm)
    {
        if ($algorithm === 'HmacSHA1') {
            $hash = 'sha1';
        } else if ($algorithm === 'HmacSHA256') {
            $hash = 'sha256';
        } else {
            throw new Exception ("Non-supported signing method specified");
        }
        return base64_encode(
            hash_hmac($hash, $data, $key, true)
        );
    }
1158591
private function processService(array &$segments): array
    {
        // init
        $processed = [];

        foreach ($segments as &$seg) {
            $jsonsegment = $this->processSegment($seg, $this->xmlSvc, null);
            $processed[$jsonsegment['key']] = $jsonsegment['value'];
        }

        return $processed;
    }
384808
private static MessageDigest create(String algorithm)
    {
        try
        {
            return MessageDigest.getInstance(algorithm);
        }
        catch (final NoSuchAlgorithmException exception)
        {
            throw new LionEngineException(exception, ERROR_ALGORITHM + algorithm);
        }
    }
665178
public function generateHash($content, $algorithm)
    {
        try {
            return $this->cryptoService->computeHash($content, $algorithm);

        } catch (Exception $exception) {
            throw new VirgilCryptoException($exception->getMessage());
        }
    }
1270892
public static function create(PrivateKey $privateKey, string $challenge = NULL, string $algorithm = NULL): Spkac {
        $spkac = openssl_spki_new($privateKey, $challenge, $algorithm);
        return new static($spkac);
    }
69120
public static function createFromSegments(iterable $segments, int $type = self::IS_RELATIVE): self
    {
        static $type_list = [self::IS_ABSOLUTE => 1, self::IS_RELATIVE => 1];

        if (!isset($type_list[$type])) {
            throw new PathTypeNotFound(sprintf('"%s" is an invalid or unsupported %s type', $type, self::class));
        }

        $pathSegments = [];
        foreach ($segments as $value) {
            if (!is_scalar($value) && !method_exists($value, '__toString')) {
                throw new TypeError('The submitted segments are invalid');
            }
            $pathSegments[] = (string) $value;
        }

        $path = implode(self::SEPARATOR, $pathSegments);
        if (static::IS_ABSOLUTE !== $type) {
            return new self(ltrim($path, self::SEPARATOR));
        }

        if (self::SEPARATOR !== ($path[0] ?? '')) {
            return new self(self::SEPARATOR.$path);
        }

        return new self($path);
    }
466335
public static PublicKey generatePublicKey(String algorithm, byte[] key) {
		if (null == key) {
			return null;
		}
		return generatePublicKey(algorithm, new X509EncodedKeySpec(key));
	}
202955
private function traverse(array $segments, &$result = array(), $node = null)
    {
        $path = array();

        if (null !== $node) {
            $path = explode('/', substr($node->getPath(), 1));
        }

        do {
            list($element, $bitmask) = array_shift($segments);

            if ($bitmask & SelectorParser::T_STATIC) {
                $path[] = $element;

                if ($bitmask & SelectorParser::T_LAST) {
                    if ($node = $this->getNode($path)) {
                        $result[] = $node;
                        break;
                    }
                }
            }

            if ($bitmask & SelectorParser::T_PATTERN) {
                if (null === $parentNode = $this->getNode($path)) {
                    return;
                }

                $children = $this->getChildren($parentNode, $element);

                foreach ($children as $child) {
                    if ($bitmask & SelectorParser::T_LAST) {
                        $result[] = $child;
                    } else {
                        $this->traverse($segments, $result, $child);
                    }
                }

                return;
            }
        } while ($segments);
    }
971821
public static KeyPair generateKeyPair(String algorithm, int keySize) {
        KeyPairGenerator keyPairGenerator;
        try {
            keyPairGenerator = KeyPairGenerator.getInstance(algorithm);
        } catch (NoSuchAlgorithmException e) {
            throw new IllegalArgumentException(e);
        }
        keyPairGenerator.initialize(keySize);
        return keyPairGenerator.generateKeyPair();
    }
1260097
public function parseKey($key)
	{
		$segments = parent::parseKey($key);

		if (is_null($segments[0])) $segments[0] = '*';

		return $segments;
	}