当前位置: 首页>>代码示例>>PHP>>正文


PHP Crypt_RSA::setHash方法代码示例

本文整理汇总了PHP中Crypt_RSA::setHash方法的典型用法代码示例。如果您正苦于以下问题:PHP Crypt_RSA::setHash方法的具体用法?PHP Crypt_RSA::setHash怎么用?PHP Crypt_RSA::setHash使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Crypt_RSA的用法示例。


在下文中一共展示了Crypt_RSA::setHash方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: initRsa

 protected function initRsa($publicKeyFile)
 {
     if (!file_exists($publicKeyFile) || !is_readable($publicKeyFile)) {
         throw new \Exception('Public key file does not exist or is not readable.');
     }
     $public_key = file_get_contents($publicKeyFile);
     $this->rsa = new \Crypt_RSA();
     $x509 = new \File_X509();
     $x509->loadX509($public_key);
     $this->rsa->loadKey($x509->getPublicKey());
     $this->rsa->setEncryptionMode(CRYPT_RSA_ENCRYPTION_PKCS1);
     $this->rsa->setHash('sha1');
 }
开发者ID:amegatron,项目名称:cryptoapi,代码行数:13,代码来源:CryptoApiHelper.php

示例2: activateKeyGen

function activateKeyGen($key, $hwid, $privKey, $offline = false)
{
    $rsa = new Crypt_RSA();
    $rsa->loadKey($privKey);
    $rsa->setSignatureMode(CRYPT_RSA_SIGNATURE_PKCS1);
    $rsa->setHash('sha512');
    $activateKey = $rsa->sign(sha1(base64_decode($key) . hash('sha512', $hwid, true)));
    if ($offline) {
        $license = '------BEGIN ACTIVATION KEY------' . "\r\n";
        $license .= chunk_split(base64_encode($activateKey));
        $license .= '------END ACTIVATION KEY------';
    } else {
        $license = base64_encode($activateKey);
    }
    return $license;
}
开发者ID:hartmantam,项目名称:php-license-system,代码行数:16,代码来源:activateKeyGenerator.php

示例3: rsa

 private function rsa($public_or_private_key, $padding_mode)
 {
     if ($public_or_private_key instanceof JOSE_JWK) {
         $rsa = $public_or_private_key->toKey();
     } else {
         if ($public_or_private_key instanceof Crypt_RSA) {
             $rsa = $public_or_private_key;
         } else {
             $rsa = new Crypt_RSA();
             $rsa->loadKey($public_or_private_key);
         }
     }
     $rsa->setHash($this->digest());
     $rsa->setMGFHash($this->digest());
     $rsa->setSignatureMode($padding_mode);
     return $rsa;
 }
开发者ID:nask0,项目名称:jose,代码行数:17,代码来源:JWS.php

示例4: CreateLicense

 public static function CreateLicense($licensee, $type)
 {
     // Gleiche Generalisierung wie am Client:
     $licenseeGen = self::GeneralizeDataString($licensee);
     $dataStr = $licenseeGen . (int) $type;
     // "ERIKAMUSTERMANN2"
     $rsa = new Crypt_RSA();
     // Neue RSA-Klasse erstellen
     // Setzen der RSA-Optionen auf die, die auch am Client verwendet werden:
     $rsa->setPrivateKeyFormat(CRYPT_RSA_PRIVATE_FORMAT_XML);
     $rsa->setHash('SHA1');
     $rsa->setSignatureMode(CRYPT_RSA_SIGNATURE_PKCS1);
     // privaten Schlüssel laden
     $rsa->loadKey(self::privateKey);
     // Erstellen der Signatur
     $signature = $rsa->sign($dataStr);
     // Formatierte Lizenzdaten zurückgeben
     return self::FormatLicense($licensee, $type, $signature);
 }
开发者ID:vainamov,项目名称:license-system,代码行数:19,代码来源:LicenseCreator.php

示例5: switch

 /**
  * Validates a signature
  *
  * Returns true if the signature is verified, false if it is not correct or NULL on error
  *
  * @param String $publicKeyAlgorithm
  * @param String $publicKey
  * @param String $signatureAlgorithm
  * @param String $signature
  * @param String $signatureSubject
  * @access private
  * @return Integer
  */
 function _validateSignature($publicKeyAlgorithm, $publicKey, $signatureAlgorithm, $signature, $signatureSubject)
 {
     switch ($publicKeyAlgorithm) {
         case 'rsaEncryption':
             require_once 'Crypt/RSA.php';
             $rsa = new Crypt_RSA();
             $rsa->loadKey($publicKey);
             switch ($signatureAlgorithm) {
                 case 'md2WithRSAEncryption':
                 case 'md5WithRSAEncryption':
                 case 'sha1WithRSAEncryption':
                 case 'sha224WithRSAEncryption':
                 case 'sha256WithRSAEncryption':
                 case 'sha384WithRSAEncryption':
                 case 'sha512WithRSAEncryption':
                     $rsa->setHash(preg_replace('#WithRSAEncryption$#', '', $signatureAlgorithm));
                     $rsa->setSignatureMode(CRYPT_RSA_SIGNATURE_PKCS1);
                     if (!@$rsa->verify($signatureSubject, $signature)) {
                         return false;
                     }
                     break;
                 default:
                     return NULL;
             }
             break;
         default:
             return NULL;
     }
     return true;
 }
开发者ID:menatwork,项目名称:phpseclib,代码行数:43,代码来源:X509.php

示例6: verifyRSAJWTsignature

 /**
  * @param string $hashtype
  * @param object $key
  * @throws OpenIDConnectClientException
  * @return bool
  */
 private function verifyRSAJWTsignature($hashtype, $key, $payload, $signature)
 {
     if (!class_exists('Crypt_RSA')) {
         throw new OpenIDConnectClientException('Crypt_RSA support unavailable.');
     }
     if (!(property_exists($key, 'n') and property_exists($key, 'e'))) {
         throw new OpenIDConnectClientException('Malformed key object');
     }
     /* We already have base64url-encoded data, so re-encode it as
           regular base64 and use the XML key format for simplicity.
        */
     $public_key_xml = "<RSAKeyValue>\r\n" . "  <Modulus>" . b64url2b64($key->n) . "</Modulus>\r\n" . "  <Exponent>" . b64url2b64($key->e) . "</Exponent>\r\n" . "</RSAKeyValue>";
     $rsa = new Crypt_RSA();
     $rsa->setHash($hashtype);
     $rsa->loadKey($public_key_xml, CRYPT_RSA_PUBLIC_FORMAT_XML);
     $rsa->signatureMode = CRYPT_RSA_SIGNATURE_PKCS1;
     return $rsa->verify($payload, $signature);
 }
开发者ID:mehrna,项目名称:OpenID-Connect-PHP,代码行数:24,代码来源:OpenIDConnectClient.php

示例7: rsa

 public function rsa($hashAlg, $key)
 {
     $rsa = new Crypt_RSA();
     $rsa->loadKey($key);
     $rsa->setHash($hashAlg);
     $rsa->setSignatureMode(CRYPT_RSA_SIGNATURE_PKCS1);
     return $rsa;
 }
开发者ID:Nikitian,项目名称:fl-ru-damp,代码行数:8,代码来源:JWS.php

示例8: getSignor

 /**
  * @param $rsaKey
  * @return \Crypt_RSA
  */
 private function getSignor($rsaKey, $password = null)
 {
     $crypt = new \Crypt_RSA();
     $crypt->loadKey($rsaKey);
     $crypt->setPassword($password);
     $crypt->setHash('sha256');
     $crypt->setSignatureMode(CRYPT_RSA_SIGNATURE_PKCS1);
     return $crypt;
 }
开发者ID:ThemeSurgeon,项目名称:launchkey-php,代码行数:13,代码来源:PhpSecLibCryptService.php

示例9: verify_signature

 public function verify_signature($message, $signature, $key, $hash_algorithm = 'sha256')
 {
     $this->ensure_crypto_loaded();
     $rsa = new Crypt_RSA();
     $rsa->setHash(strtolower($hash_algorithm));
     // This is not the default, but is what we use
     $rsa->setSignatureMode(CRYPT_RSA_SIGNATURE_PKCS1);
     $rsa->loadKey($key);
     // Don't hash it - Crypt_RSA::verify() already does that
     // 		$hash = new Crypt_Hash($hash_algorithm);
     // 		$hashed = $hash->hash($message);
     $verified = $rsa->verify($message, base64_decode($signature));
     if ($this->debug) {
         $this->log('Signature verification result: ' . serialize($verified));
     }
     return $verified;
 }
开发者ID:aaronfrey,项目名称:PepperLillie-Cambridge,代码行数:17,代码来源:class-udrpc.php

示例10: verify_phpseclib

 protected function verify_phpseclib($data, $sigBin, $publickey, $algo = 'sha256WithRSAEncryption')
 {
     $isHash = preg_match("/^([a-z]+[0-9]).+/", $algo, $hashinfo);
     $hash = $isHash ? $hashinfo[1] : 'sha256';
     $rsa = new Crypt_RSA();
     $rsa->setHash($hash);
     $rsa->setSignatureMode(CRYPT_RSA_SIGNATURE_PKCS1);
     $rsa->setEncryptionMode(CRYPT_RSA_ENCRYPTION_PKCS1);
     $rsa->loadKey($publickey);
     return $rsa->verify($data, $sigBin) === TRUE ? TRUE : FALSE;
 }
开发者ID:frdl,项目名称:webfan,代码行数:11,代码来源:SourceLoader.php

示例11:

<?php

set_time_limit(0);
if (file_exists('private.key')) {
    echo base64_encode(file_get_contents('private.key'));
} else {
    include 'Crypt/RSA.php';
    $rsa = new Crypt_RSA();
    $rsa->setHash('sha1');
    $rsa->setMGFHash('sha1');
    $rsa->setEncryptionMode(CRYPT_RSA_ENCRYPTION_OAEP);
    $rsa->setPrivateKeyFormat(CRYPT_RSA_PRIVATE_FORMAT_PKCS1);
    $rsa->setPublicKeyFormat(CRYPT_RSA_PUBLIC_FORMAT_PKCS1);
    $res = $rsa->createKey(1024);
    $privateKey = $res['privatekey'];
    $publicKey = $res['publickey'];
    file_put_contents('public.key', $publicKey);
    file_put_contents('private.key', $privateKey);
    echo base64_encode($privateKey);
}
开发者ID:fajarlabs,项目名称:php_security,代码行数:20,代码来源:keypair.php

示例12: loadKey

 /**
  * Fill out $this->privateKey or $this->publicKey with a Crypt_RSA object
  * representing the give key (as mod/exponent pair).
  *
  * @param string $mod base64-encoded
  * @param string $exp base64-encoded exponent
  * @param string $type one of 'public' or 'private'
  */
 public function loadKey($mod, $exp, $type = 'public')
 {
     common_log(LOG_DEBUG, "Adding " . $type . " key: (" . $mod . ', ' . $exp . ")");
     $rsa = new Crypt_RSA();
     $rsa->signatureMode = CRYPT_RSA_SIGNATURE_PKCS1;
     $rsa->setHash('sha256');
     $rsa->modulus = new Math_BigInteger(Magicsig::base64_url_decode($mod), 256);
     $rsa->k = strlen($rsa->modulus->toBytes());
     $rsa->exponent = new Math_BigInteger(Magicsig::base64_url_decode($exp), 256);
     if ($type == 'private') {
         $this->privateKey = $rsa;
     } else {
         $this->publicKey = $rsa;
     }
 }
开发者ID:microcosmx,项目名称:experiments,代码行数:23,代码来源:Magicsig.php

示例13: die

<?php

include 'Crypt/RSA.php';
$rsa = new Crypt_RSA();
$msg = "";
$color = "";
$cisti_tekst = file_get_contents('./cisti_tekst.txt', FILE_USE_INCLUDE_PATH);
if (isset($_POST['potpisi'])) {
    file_put_contents('potpis.txt', '');
    $cisti_tekst = file_get_contents('./cisti_tekst.txt', FILE_USE_INCLUDE_PATH);
    $rsa->setHash("sha256");
    $rsa->setSignatureMode(CRYPT_RSA_SIGNATURE_PKCS1);
    $privatekey = file_get_contents('./privatni_kljuc.txt', FILE_USE_INCLUDE_PATH);
    $rsa->loadKey($privatekey);
    //$signature = base64_encode($rsa->sign(base64_decode($cisti_tekst)));
    //$signature = base64_encode($rsa->sign(base64_decode($cisti_tekst)));
    $signature = $rsa->sign($cisti_tekst);
    $signature = base64_encode($signature);
    $ret = file_put_contents('potpis.txt', $signature, FILE_APPEND | LOCK_EX);
    if ($ret === false) {
        die('Neuspješna pohrana u datoteku');
    } else {
        echo "U datoteku je pohranjeno: " . $ret . " bajtova";
    }
}
if (isset($_POST['provjeri'])) {
    $rsa->setHash("sha256");
    $rsa->setSignatureMode(CRYPT_RSA_SIGNATURE_PKCS1);
    $publickey = file_get_contents('./javni_kljuc.txt', FILE_USE_INCLUDE_PATH);
    $rsa->loadKey($publickey);
    $signature = file_get_contents('./potpis.txt', FILE_USE_INCLUDE_PATH);
开发者ID:jtrupina,项目名称:os2-project,代码行数:31,代码来源:digitalnipotpis.php

示例14: switch

 /**
  * Validates a signature
  *
  * Returns true if the signature is verified, false if it is not correct or null on error
  *
  * @param String $publicKeyAlgorithm
  * @param String $publicKey
  * @param String $signatureAlgorithm
  * @param String $signature
  * @param String $signatureSubject
  * @access private
  * @return Integer
  */
 function _validateSignature($publicKeyAlgorithm, $publicKey, $signatureAlgorithm, $signature, $signatureSubject)
 {
     switch ($publicKeyAlgorithm) {
         case 'rsaEncryption':
             if (!class_exists('Crypt_RSA')) {
                 include_once EASYWIDIR . '/third_party/phpseclib/Crypt/RSA.php';
             }
             $rsa = new Crypt_RSA();
             $rsa->loadKey($publicKey);
             switch ($signatureAlgorithm) {
                 case 'md2WithRSAEncryption':
                 case 'md5WithRSAEncryption':
                 case 'sha1WithRSAEncryption':
                 case 'sha224WithRSAEncryption':
                 case 'sha256WithRSAEncryption':
                 case 'sha384WithRSAEncryption':
                 case 'sha512WithRSAEncryption':
                     $rsa->setHash(preg_replace('#WithRSAEncryption$#', '', $signatureAlgorithm));
                     $rsa->setSignatureMode(CRYPT_RSA_SIGNATURE_PKCS1);
                     if (!@$rsa->verify($signatureSubject, $signature)) {
                         return false;
                     }
                     break;
                 default:
                     return null;
             }
             break;
         default:
             return null;
     }
     return true;
 }
开发者ID:nightcore125,项目名称:developer,代码行数:45,代码来源:X509.php

示例15: loadKey

 /**
  * Fill out $this->privateKey or $this->publicKey with a Crypt_RSA object
  * representing the give key (as mod/exponent pair).
  *
  * @param string $mod base64-encoded
  * @param string $exp base64-encoded exponent
  * @param string $type one of 'public' or 'private'
  */
 public function loadKey($mod, $exp, $type = 'public')
 {
     $rsa = new Crypt_RSA();
     $rsa->setSignatureMode(CRYPT_RSA_SIGNATURE_PKCS1);
     $rsa->setHash($this->getHash());
     $rsa->modulus = new Math_BigInteger(Magicsig::base64_url_decode($mod), 256);
     $rsa->k = strlen($rsa->modulus->toBytes());
     $rsa->exponent = new Math_BigInteger(Magicsig::base64_url_decode($exp), 256);
     if ($type == 'private') {
         $this->privateKey = $rsa;
     } else {
         $this->publicKey = $rsa;
     }
 }
开发者ID:phpsource,项目名称:gnu-social,代码行数:22,代码来源:Magicsig.php


注:本文中的Crypt_RSA::setHash方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。