Get OpenSSL digest method for given signature algorithm identifier.

@param SignatureAlgorithmIdentifier $algo
@throws \UnexpectedValueException
@return string
14657
protected function _algoToDigest(SignatureAlgorithmIdentifier $algo): string
    {
        $oid = $algo->oid();
        if (!array_key_exists($oid, self::MAP_DIGEST_OID_TO_NAME)) {
            throw new \UnexpectedValueException(
                sprintf('Digest method %s not supported.', $algo->name()));
        }
        return self::MAP_DIGEST_OID_TO_NAME[$oid];
    }
930341
private function getEncryptedHash()
    {
        $signature = '';
        $pkeyId = openssl_get_privatekey($this->privateKey);
        if (!$pkeyId) {
            throw new Swift_SwiftException('Unable to load DomainKey Private Key ['.openssl_error_string().']');
        }
        if (openssl_sign($this->canonData, $signature, $pkeyId, OPENSSL_ALGO_SHA1)) {
            return $signature;
        }
        throw new Swift_SwiftException('Unable to sign DomainKey Hash  ['.openssl_error_string().']');
    }
197734
public static function decrypt($text, $key, $algo = MCRYPT_RIJNDAEL_256, $mode = MCRYPT_MODE_CBC)
        {
            $hash = substr($text, 0, 64);
            $text = substr($text, 64);

            // Invalid HMAC?
            if(hash('sha256', $key . $text) != $hash) {
                return;
            }

            // Get IV off end of encrypted string
            $iv = substr($text, -mcrypt_get_iv_size($algo, $mode));

            // Decrypt string using IV and remove trailing \x0 padding added by mcrypt
            return rtrim(
                mcrypt_decrypt(
                    $algo,
                    hash('sha256', $key, true),
                    substr($text, 0, -strlen($iv)),
                    $mode,
                    $iv
                ),
                "\x0"
            );
        }
849600
public function hash($algo = 'md5', $raw_output = false)
	{
		return hash($algo, $this->date->format('Y-m-d'), $raw_output);
	}
709974
public static function HmacBinaryStretching ($count, $data, $key, $algo = self::DEFAULT_HASH_ALGORITHM) {
		for ($i = 0;$i < $count;$i++) {
			$data = static::HmacBinary($data, $key, $algo);
		}
		return $data;
	}
461973
private function getAuthenticator(): IAuthenticator
	{
		$ns = $this->userStorage->getNamespace();
		if (isset($this->mapper[$ns])) {
			$ns = $this->mapper[$ns];
		}
		if (!isset($this->authenticators[$ns])) {
			throw new UnexpectedValueException("Namespace '$ns' is not registered");
		}
		return $this->authenticators[$ns];
	}
654837
public function encryptString($algo, $string, $key = null)
    {     
        if (!empty($algo) && !empty($string)) {   
            if ($key == null) {
                $ctx = hash_init($algo);
            } else {
                $ctx = hash_init($algo, HASH_HMAC, $key);
                hash_update($ctx, $string);
            }
            return hash_final($ctx);
        }
        return false;
    }
1220891
public static function hash( string $algo = 'sha1', string $data = NULL )
    {
        if (!$data){
            $data = microtime().uniqid(mt_rand(),1);
        }
        return hash( $algo, $data );
    }
1022704
public function sign(SignatureAlgorithmIdentifier $algo,
        PrivateKeyInfo $privkey_info, Crypto $crypto = null): Certificate
    {
        $crypto = $crypto ?: Crypto::getDefault();
        $tbs_cert = clone $this;
        if (!isset($tbs_cert->_version)) {
            $tbs_cert->_version = $tbs_cert->_determineVersion();
        }
        if (!isset($tbs_cert->_serialNumber)) {
            $tbs_cert->_serialNumber = strval(0);
        }
        $tbs_cert->_signature = $algo;
        $data = $tbs_cert->toASN1()->toDER();
        $signature = $crypto->sign($data, $privkey_info, $algo);
        return new Certificate($tbs_cert, $algo, $signature);
    }
697723
public static function opensslVerify(
        $str,
        $sinature,
        $publicKeyPath,
        $algo = OPENSSL_ALGO_SHA1,
        $format = self::FORMAT_HEX
    )
    {
        $publicKey = openssl_pkey_get_public(file_get_contents($publicKeyPath));

        $sinature = trim($sinature);

        switch ($format) {
            case self::FORMAT_HEX:
                $sinature = hex2bin($sinature);
                break;
            case self::FORMAT_BASE64:
                $sinature = EncodeHelper::base64Decode($sinature);
                break;
            default:
                $sinature = hex2bin($sinature);
        }

        $res = openssl_verify(trim($str), $sinature, $publicKey, $algo);

        openssl_free_key($publicKey);

        if ($res == 1) {
            return true;
        }

        return false;
    }
717571
def signature_algo(self):
        

        algorithm = self['algorithm'].native

        algo_map = {
            'md2_rsa': 'rsassa_pkcs1v15',
            'md5_rsa': 'rsassa_pkcs1v15',
            'sha1_rsa': 'rsassa_pkcs1v15',
            'sha224_rsa': 'rsassa_pkcs1v15',
            'sha256_rsa': 'rsassa_pkcs1v15',
            'sha384_rsa': 'rsassa_pkcs1v15',
            'sha512_rsa': 'rsassa_pkcs1v15',
            'rsassa_pkcs1v15': 'rsassa_pkcs1v15',
            'rsassa_pss': 'rsassa_pss',
            'sha1_dsa': 'dsa',
            'sha224_dsa': 'dsa',
            'sha256_dsa': 'dsa',
            'dsa': 'dsa',
            'sha1_ecdsa': 'ecdsa',
            'sha224_ecdsa': 'ecdsa',
            'sha256_ecdsa': 'ecdsa',
            'sha384_ecdsa': 'ecdsa',
            'sha512_ecdsa': 'ecdsa',
            'sha3_224_ecdsa': 'ecdsa',
            'sha3_256_ecdsa': 'ecdsa',
            'sha3_384_ecdsa': 'ecdsa',
            'sha3_512_ecdsa': 'ecdsa',
            'ecdsa': 'ecdsa',
        }
        if algorithm in algo_map:
            return algo_map[algorithm]

        raise ValueError(unwrap(
            '''
            Signature algorithm not known for %s
            ''',
            algorithm
        ))
97031
function(algo) {
    switch (algo) {
      //   Algorithm-Specific Fields for RSA encrypted session keys:
      //       - MPI of RSA encrypted value m**e mod n.
      case enums.publicKey.rsa_encrypt:
      case enums.publicKey.rsa_encrypt_sign:
        return [type_mpi];

      //   Algorithm-Specific Fields for Elgamal encrypted session keys:
      //       - MPI of Elgamal value g**k mod p
      //       - MPI of Elgamal value m * y**k mod p
      case enums.publicKey.elgamal:
        return [type_mpi, type_mpi];
      //   Algorithm-Specific Fields for ECDH encrypted session keys:
      //       - MPI containing the ephemeral key used to establish the shared secret
      //       - ECDH Symmetric Key
      case enums.publicKey.ecdh:
        return [type_mpi, type_ecdh_symkey];
      default:
        throw new Error('Invalid public key encryption algorithm.');
    }
  }
436446
private function getAlgorithm(Object\SignatureInterface $signature)
    {
        $complete_headers = array_merge(
            $signature->getProtectedHeaders(),
            $signature->getHeaders()
        );
        Assertion::keyExists($complete_headers, 'alg', 'No "alg" parameter set in the header.');

        $algorithm = $this->getJWAManager()->getAlgorithm($complete_headers['alg']);
        Assertion::isInstanceOf($algorithm, Algorithm\SignatureAlgorithmInterface::class, sprintf('The algorithm "%s" is not supported or does not implement SignatureInterface.', $complete_headers['alg']));

        return $algorithm;
    }
1158532
public function getFingerprint($alg = 'sha256')
    {
        if (!in_array($alg, hash_algos())) {
            throw new RuntimeException(
                sprintf(
                    'unsupported algorithm "%s"',
                    $alg
                )
            );
        }

        return hash($alg, $this->toDer(), true);
    }
1069441
public static function hash($object, $algoOrCtx = 'md5', $raw = FALSE)
	{
		if (is_string($algoOrCtx)) {
			$ctx = hash_init($algoOrCtx);
		} else {
			$ctx = $algoOrCtx;
		}

		if (isset($object->name)) {
			hash_update($ctx, 'name');
			hash_update($ctx, (string)$object->name);
		}

		if (isset($object->value)) {
			hash_update($ctx, 'value');
			foreach ($object->value instanceof \Traversable ? $object->value : (array)$object->value as $v0) {
				EnumValueDescriptorProtoMeta::hash($v0, $ctx);
			}
		}

		if (isset($object->options)) {
			hash_update($ctx, 'options');
			EnumOptionsMeta::hash($object->options, $ctx);
		}

		if (is_string($algoOrCtx)) {
			return hash_final($ctx, $raw);
		} else {
			return null;
		}
	}
226013
protected function getSigner()
    {
        $signerClass = sprintf('Namshi\\JOSE\\Signer\\%s\\%s', $this->encryptionEngine, $this->header['alg']);

        if (class_exists($signerClass)) {
            return new $signerClass();
        }

        throw new InvalidArgumentException(
            sprintf("The algorithm '%s' is not supported for %s", $this->header['alg'], $this->encryptionEngine));
    }
991591
public function hash($string, $algo)
    {
        if (true === empty($string)) {
            $string = microtime() . uniqid();
        }

        return hash($algo, $string);
    }