本文整理汇总了PHP中openssl_get_md_methods函数的典型用法代码示例。如果您正苦于以下问题:PHP openssl_get_md_methods函数的具体用法?PHP openssl_get_md_methods怎么用?PHP openssl_get_md_methods使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了openssl_get_md_methods函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: verify
/**
* Verifies that the data and the signature belong to this public key.
* Returns true on success, false on failure.
* @param mixed $data The data to be verified
* @param mixed $signature The signature of the data
* @param string $algoritm Which algorithm to use for signing
* @return boolean
* @throws InvalidMessageDigestAlgorithmException
*/
public function verify($data, $signature, $algorithm = 'RSA-SHA256')
{
if (!in_array($algorithm, openssl_get_md_methods(true))) {
throw new InvalidMessageDigestAlgorithmException("The digest algorithm '{$algorithm}' is not supported by this openssl implementation.");
}
return openssl_verify($data, $signature, $this->keyResource, $algorithm) == 1;
}
示例2: getSupportedAlgs
public function getSupportedAlgs()
{
$results = array();
$hashes = array();
$hash_algos = openssl_get_md_methods();
if (in_array('SHA256', $hash_algos)) {
$hashes[] = 256;
}
if (in_array('SHA384', $hash_algos)) {
$hashes[] = 384;
}
if (in_array('SHA512', $hash_algos)) {
$hashes[] = 512;
}
if (defined('OPENSSL_KEYTYPE_RSA')) {
foreach ($hashes as $size) {
$results[] = 'RS' . $size;
}
}
if (defined('OPENSSL_KEYTYPE_EC')) {
foreach ($hashes as $size) {
$results[] = 'ES' . $size;
}
}
return $results;
}
示例3: ensureSupport
/**
* @throws \RuntimeException
*/
private function ensureSupport()
{
if (!function_exists('openssl_sign')) {
throw new \RuntimeException('Openssl is required to use RSA encryption.');
}
if (!in_array($this->getAlgorithm(), openssl_get_md_methods(true))) {
throw new \RuntimeException('Algorithm "%s" is not supported.', $this->getAlgorithm());
}
}
示例4: getOpenSSLAlgorithm
/**
* @return string
* @throws EncryptionNotSupported
*/
protected function getOpenSSLAlgorithm()
{
$algorithms = openssl_get_md_methods();
$algorithm = $this->getAlgorithm();
if (in_array($algorithm, $algorithms) === false) {
throw new EncryptionNotSupported("Algorithm {$algorithm} is not supported.");
}
return $algorithm;
}
示例5: ensureSupport
/**
* @throws \RuntimeException
*/
public function ensureSupport()
{
if (!function_exists('openssl_sign')) {
throw new \RuntimeException('Openssl is required to use RSA encryption.');
}
$supportedAlgorithms = openssl_get_md_methods(true);
if (!in_array($this->getAlgorithm(), $supportedAlgorithms)) {
throw new \RuntimeException('Algorithm "%s" is not supported on this system.', $this->getAlgorithm());
}
}
示例6: getFavorite
private function getFavorite()
{
if (null !== $this->favorite) {
return $this->favorite;
}
if (function_exists('hash_algos') && in_array($this->type, hash_algos(), true)) {
return $this->favorite = 'hash';
}
if (function_exists('openssl_get_md_methods') && in_array($this->type, openssl_get_md_methods(), true)) {
return $this->favorite = 'openssl';
}
}
示例7: isAlgorithmSupported
/**
* @return boolean
*/
private static function isAlgorithmSupported($algorithm)
{
if (!self::$supportedAlgorithms) {
$supportedAlgorithms = openssl_get_md_methods(true);
$constants = array('OPENSSL_ALGO_DSS1', 'OPENSSL_ALGO_SHA1', 'OPENSSL_ALGO_SHA224', 'OPENSSL_ALGO_SHA256', 'OPENSSL_ALGO_SHA384', 'OPENSSL_ALGO_SHA512', 'OPENSSL_ALGO_RMD160', 'OPENSSL_ALGO_MD5', 'OPENSSL_ALGO_MD4', 'OPENSSL_ALGO_MD2');
foreach ($constants as $constant) {
if (defined($constant)) {
$supportedAlgorithms[] = constant($constant);
}
}
self::$supportedAlgorithms = $supportedAlgorithms;
}
return in_array($algorithm, self::$supportedAlgorithms);
}
示例8: getHashSelect
protected function getHashSelect($name)
{
$select = new \Zend\Form\Element\Select($name);
$select->setAttributes(array('id' => $name));
$select->setLabel('Digest Algorithm');
$select->setEmptyOption('-- Select Digest Algorithm --');
$algos = openssl_get_md_methods();
$hashes = array();
foreach ($algos as $hash) {
$upper = strtoupper($hash);
if (defined('OPENSSL_ALGO_' . $upper)) {
$hashes[$upper] = $upper;
}
}
$select->setValueOptions($hashes);
$select->setValue('SHA1');
return $select;
}
示例9: __construct
public function __construct()
{
global $mtlda, $config;
if (!$config->isPdfSigningEnabled()) {
static::raiseError("PdfSigningController, pdf_signing not enabled in config.ini!");
return false;
}
if (!($this->pdf_cfg = $config->getPdfSigningConfiguration())) {
static::raiseError("PdfSigningController, pdf_signing enabled but no valid [pdf_signing] section found!");
return false;
}
if (!($this->tsp_cfg = $config->getTimestampConfiguration())) {
$this->tsp_cfg = array('tsp_algorithm' => 'SHA256');
}
if (!isset($this->pdf_cfg['signature_algorithm']) || empty($this->pdf_cfg['signature_algorithm'])) {
$this->pdf_cfg['signature_algorithm'] = 'SHA256';
}
// check if tsp algorithm is supported by the local OpenSSL installation
if (!preg_match('/^SHA(1|256)$/', $this->tsp_cfg['tsp_algorithm'])) {
static::raiseError("TSP algorithm {$this->tsp_cfg['tsp_algorithm']} is not supported!");
return false;
}
$supported_alg = openssl_get_md_methods(true);
if (empty($supported_alg) || !is_array($supported_alg)) {
static::raiseError("Unable to retrive supported digest algorithms via openssl_get_md_methods()!");
return false;
}
$this->tsp_digest_algorithm = strtolower($this->tsp_cfg['tsp_algorithm']) . 'WithRSAEncryption';
if (!in_array($this->tsp_digest_algorithm, $supported_alg)) {
static::raiseError("OpenSSL installation does not support {$this->tsp_digest_algorithm} digest algorithm!");
return false;
}
$fields = array('author', 'location', 'reason', 'contact', 'certificate', 'private_key');
foreach ($fields as $field) {
if (!isset($this->pdf_cfg[$field]) || empty($this->pdf_cfg[$field])) {
static::raiseError("PdfSigningController, {$field} not found in section [pdf_signing]!");
return false;
}
}
}
示例10: execute
//.........这里部分代码省略.........
}
$latest = $versionsUtil->getLatest();
$latestVersion = $latest['version'];
$updateVersion = $input->getArgument('version') ?: $latestVersion;
if (preg_match('{^[0-9a-f]{40}$}', $updateVersion) && $updateVersion !== $latestVersion) {
$io->writeError('<error>You can not update to a specific SHA-1 as those phars are not available for download</error>');
return 1;
}
if (Composer::VERSION === $updateVersion) {
$io->writeError('<info>You are already using composer version ' . $updateVersion . '.</info>');
// remove all backups except for the most recent, if any
if ($input->getOption('clean-backups')) {
$this->cleanBackups($rollbackDir, $this->getLastBackupVersion($rollbackDir));
}
return 0;
}
$tempFilename = $tmpDir . '/' . basename($localFilename, '.phar') . '-temp.phar';
$backupFile = sprintf('%s/%s-%s%s', $rollbackDir, strtr(Composer::RELEASE_DATE, ' :', '_-'), preg_replace('{^([0-9a-f]{7})[0-9a-f]{33}$}', '$1', Composer::VERSION), self::OLD_INSTALL_EXT);
$updatingToTag = !preg_match('{^[0-9a-f]{40}$}', $updateVersion);
$io->write(sprintf("Updating to version <info>%s</info>.", $updateVersion));
$remoteFilename = $baseUrl . ($updatingToTag ? "/download/{$updateVersion}/composer.phar" : '/composer.phar');
$signature = $remoteFilesystem->getContents(self::HOMEPAGE, $remoteFilename . '.sig', false);
$remoteFilesystem->copy(self::HOMEPAGE, $remoteFilename, $tempFilename, !$input->getOption('no-progress'));
if (!file_exists($tempFilename) || !$signature) {
$io->writeError('<error>The download of the new composer version failed for an unexpected reason</error>');
return 1;
}
// verify phar signature
if (!extension_loaded('openssl') && $config->get('disable-tls')) {
$io->writeError('<warning>Skipping phar signature verification as you have disabled OpenSSL via config.disable-tls</warning>');
} else {
if (!extension_loaded('openssl')) {
throw new \RuntimeException('The openssl extension is required for phar signatures to be verified but it is not available. ' . 'If you can not enable the openssl extension, you can disable this error, at your own risk, by setting the \'disable-tls\' option to true.');
}
$sigFile = 'file://' . $home . '/' . ($updatingToTag ? 'keys.tags.pub' : 'keys.dev.pub');
if (!file_exists($sigFile)) {
file_put_contents($home . '/keys.dev.pub', <<<DEVPUBKEY
-----BEGIN PUBLIC KEY-----
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAnBDHjZS6e0ZMoK3xTD7f
FNCzlXjX/Aie2dit8QXA03pSrOTbaMnxON3hUL47Lz3g1SC6YJEMVHr0zYq4elWi
i3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otZGPR4KsVj8NnBrLX7oGuM
nQvGciiu+KoC2r3HDBrpDeBVdOWxDzT5R4iI0KoLzFh2pKqwbY+obNPS2bj+2dgJ
rV3V5Jjry42QOCBN3c88wU1PKftOLj2ECpewY6vnE478IipiEu7EAdK8Zwj2LmTr
RKQUSa9k7ggBkYZWAeO/2Ag0ey3g2bg7eqk+sHEq5ynIXd5lhv6tC5PBdHlWipDK
tl2IxiEnejnOmAzGVivE1YGduYBjN+mjxDVy8KGBrjnz1JPgAvgdwJ2dYw4Rsc/e
TzCFWGk/HM6a4f0IzBWbJ5ot0PIi4amk07IotBXDWwqDiQTwyuGCym5EqWQ2BD95
RGv89BPD+2DLnJysngsvVaUCAwEAAQ==
-----END PUBLIC KEY-----
TAGSPUBKEY
);
}
$pubkeyid = openssl_pkey_get_public($sigFile);
$algo = defined('OPENSSL_ALGO_SHA384') ? OPENSSL_ALGO_SHA384 : 'SHA384';
if (!in_array('SHA384', openssl_get_md_methods())) {
throw new \RuntimeException('SHA384 is not supported by your openssl extension, could not verify the phar file integrity');
}
$signature = json_decode($signature, true);
$signature = base64_decode($signature['sha384']);
$verified = 1 === openssl_verify(file_get_contents($tempFilename), $signature, $pubkeyid, $algo);
openssl_free_key($pubkeyid);
if (!$verified) {
throw new \RuntimeException('The phar signature did not match the file you downloaded, this means your public keys are outdated or that the phar file is corrupt/has been modified');
}
}
// remove saved installations of composer
if ($input->getOption('clean-backups')) {
$this->cleanBackups($rollbackDir);
}
if ($err = $this->setLocalPhar($localFilename, $tempFilename, $backupFile)) {
@unlink($tempFilename);
$io->writeError('<error>The file is corrupted (' . $err->getMessage() . ').</error>');
$io->writeError('<error>Please re-run the self-update command to try again.</error>');
return 1;
}
if (file_exists($backupFile)) {
$io->writeError('Use <info>composer self-update --rollback</info> to return to version ' . Composer::VERSION);
} else {
$io->writeError('<warning>A backup of the current version could not be written to ' . $backupFile . ', no rollback possible</warning>');
}
}
示例11: openssl_get_md_methods
<?php
$digests = openssl_get_md_methods();
$digests_and_aliases = openssl_get_md_methods(true);
$digest_aliases = array_diff($digests_and_aliases, $digests);
print_r($digests);
print_r($digest_aliases);
示例12: installComposer
//.........这里部分代码省略.........
}
if (!$version) {
throw new RuntimeException('There is no version of Composer available for your PHP version (' . PHP_VERSION . ')');
}
} else {
$downloadUrl = "/download/{$version}/composer.phar";
}
$retries = 3;
while ($retries--) {
if (!$quiet) {
out("Downloading {$version}...", 'info');
}
$url = "{$uriScheme}://getcomposer.org{$downloadUrl}";
$errorHandler = new ErrorHandler();
set_error_handler(array($errorHandler, 'handleError'));
// download signature file
if (false === $disableTls) {
$signature = $httpClient->get($url . '.sig');
if (!$signature) {
out('Download failed: ' . $errorHandler->message, 'error');
} else {
$signature = json_decode($signature, true);
$signature = base64_decode($signature['sha384']);
}
}
$fh = fopen($file, 'w');
if (!$fh) {
out('Could not create file ' . $file . ': ' . $errorHandler->message, 'error');
}
if (!fwrite($fh, $httpClient->get($url))) {
out('Download failed: ' . $errorHandler->message, 'error');
}
fclose($fh);
restore_error_handler();
if ($errorHandler->message) {
continue;
}
try {
// create a temp file ending in .phar since the Phar class only accepts that
if ('.phar' !== substr($file, -5)) {
copy($file, $file . '.tmp.phar');
$pharFile = $file . '.tmp.phar';
} else {
$pharFile = $file;
}
// verify signature
if (false === $disableTls) {
$pubkeyid = openssl_pkey_get_public('file://' . $home . '/' . (preg_match('{^[0-9a-f]{40}$}', $version) ? 'keys.dev.pub' : 'keys.tags.pub'));
$algo = defined('OPENSSL_ALGO_SHA384') ? OPENSSL_ALGO_SHA384 : 'SHA384';
if (!in_array('SHA384', openssl_get_md_methods())) {
out('SHA384 is not supported by your openssl extension, could not verify the phar file integrity', 'error');
exit(1);
}
$verified = 1 === openssl_verify(file_get_contents($file), $signature, $pubkeyid, $algo);
openssl_free_key($pubkeyid);
if (!$verified) {
out('Signature mismatch, could not verify the phar file integrity', 'error');
exit(1);
}
}
// test the phar validity
if (!ini_get('phar.readonly')) {
$phar = new Phar($pharFile);
// free the variable to unlock the file
unset($phar);
}
// clean up temp file if needed
if ($file !== $pharFile) {
unlink($pharFile);
}
break;
} catch (Exception $e) {
if (!$e instanceof UnexpectedValueException && !$e instanceof PharException) {
throw $e;
}
// clean up temp file if needed
if ($file !== $pharFile) {
unlink($pharFile);
}
unlink($file);
if ($retries) {
if (!$quiet) {
out('The download is corrupt, retrying...', 'error');
}
} else {
out('The download is corrupt (' . $e->getMessage() . '), aborting.', 'error');
exit(1);
}
}
}
if ($errorHandler->message) {
out('The download failed repeatedly, aborting.', 'error');
exit(1);
}
chmod($file, 0755);
if (!$quiet) {
out(PHP_EOL . "Composer successfully installed to: " . $file, 'success', false);
out(PHP_EOL . "Use it: php {$installPath}", 'info');
}
}
示例13: getMdMethods
public static function getMdMethods($aliases = false)
{
return openssl_get_md_methods($aliases);
}
示例14: setHashAlgorithm
/**
* Set hash algorithm
*
* @param string $name
* @throws InvalidArgumentException
*/
public function setHashAlgorithm($name)
{
switch (strtolower($name)) {
case 'md2':
// check if md2 digest is enabled on openssl just for backwards compatibility
$digests = openssl_get_md_methods();
if (!in_array(strtoupper($name), $digests)) {
throw new InvalidArgumentException('Openssl md2 digest is not enabled (deprecated)');
}
$this->_hashAlgorithm = OPENSSL_ALGO_MD2;
break;
case 'md4':
$this->_hashAlgorithm = OPENSSL_ALGO_MD4;
break;
case 'md5':
$this->_hashAlgorithm = OPENSSL_ALGO_MD5;
break;
case 'sha1':
$this->_hashAlgorithm = OPENSSL_ALGO_SHA1;
break;
case 'dss1':
$this->_hashAlgorithm = OPENSSL_ALGO_DSS1;
break;
}
}
示例15: getDigestMethods
/**
* @param bool $aliases
*
* @return array
*/
public static function getDigestMethods(bool $aliases = FALSE) : array
{
return openssl_get_md_methods($aliases);
}