• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP hash_pbkdf2函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中hash_pbkdf2函数的典型用法代码示例。如果您正苦于以下问题:PHP hash_pbkdf2函数的具体用法?PHP hash_pbkdf2怎么用?PHP hash_pbkdf2使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: crack_keystore

/**
 * crack_keystore
 *
 * Makes a bruteforce to find the final hash contained in the KeyStore
 * Returns the plaintext password used to encrypt de disk of the virtual machine
 */
function crack_keystore($keystore, $wordlist)
{
    // Open wordlist file
    $fp = fopen($wordlist, 'r');
    // Continue if it is a valid resource
    if (is_resource($fp)) {
        // Get hash and method from keystore
        $hash = get_hash_algorithm($keystore);
        $method = get_openssl_method($keystore);
        while (!feof($fp)) {
            // Read each line of the file, it is the user password
            $user_password = trim(fgets($fp));
            // First call to PBKDF2
            $EVP_password = hash_pbkdf2($hash, $user_password, $keystore['pbkdf2_1_salt'], $keystore['pbkdf2_1_iterations'], $keystore['generic_key_length'], true);
            // Here, the password used for the second call to PBKDF2 is decrypted
            $decrypted_password = openssl_decrypt(substr($keystore['pbkdf2_2_encrypted_password'], 0, $keystore['evp_decrypt_input_length']), $method, $EVP_password, OPENSSL_RAW_DATA, '');
            if ($decrypted_password === false) {
                continue;
            }
            // Final hash is computed
            $final_hash = hash_pbkdf2($hash, $decrypted_password, $keystore['pbkdf2_2_salt'], $keystore['pbkdf2_2_iterations'], $keystore['pbkdf2_2_key_length'], true);
            // If the computed hash is equal to the stored hash, then we have got the right user password
            if ($final_hash === $keystore['final_hash']) {
                return $user_password;
            }
        }
        return false;
    } else {
        return false;
    }
}
开发者ID:sinfocol,项目名称:vboxdie-cracker,代码行数:37,代码来源:VBOXDIECracker.php


示例2: setUp

 /**
  * set up for dependent objects before running each test
  */
 public final function setUp()
 {
     //run default set-up method
     parent::setUp();
     //create a new organization for the test volunteers to belong
     $organization = new Organization(null, "123 Easy Street", '', "Albuquerque", "Feeding people since 1987", "9 - 5", "Food for Hungry People", "505-765-4321", "NM", "R", "87801");
     $organization->insert($this->getPDO());
     //create a new volunteer to use as an admin for the tests
     //don't need to insert them into the database: just need their info to create sessions
     //for testing purposes, allow them to create organizations they're not associated with
     $salt = bin2hex(openssl_random_pseudo_bytes(32));
     $hash = hash_pbkdf2("sha512", "password4321", $salt, 262144, 128);
     $this->admin = new Volunteer(null, $organization->getOrgId(), "[email protected]", null, "John", $hash, true, "Doe", "505-123-4567", $salt);
     $this->admin->insert($this->getPDO());
     //create a non-admin volunteer for the tests
     $salt = bin2hex(openssl_random_pseudo_bytes(32));
     $hash = hash_pbkdf2("sha512", "password1234", $salt, 262144, 128);
     $this->volunteer = new Volunteer(null, $organization->getOrgId(), "[email protected]", null, "Jane", $hash, false, "Doe", "505-555-5555", $salt);
     $this->volunteer->insert($this->getPDO());
     //create the guzzle client
     $this->guzzle = new \GuzzleHttp\Client(["cookies" => true]);
     //visit ourselves to get the xsrf-token
     $this->guzzle->get('https://bootcamp-coders.cnm.edu/~tfenstermaker/bread-basket/public_html/php/api/organization');
     $cookies = $this->guzzle->getConfig()["cookies"];
     $this->token = $cookies->getCookieByName("XSRF-TOKEN")->getValue();
     //send a request to the sign-in method
     $adminLogin = new stdClass();
     $adminLogin->email = "[email protected]";
     $adminLogin->password = "password4321";
     $login = $this->guzzle->post('https://bootcamp-coders.cnm.edu/~tfenstermaker/bread-basket/public_html/php/controllers/sign-in-controller.php', ['json' => $adminLogin, 'headers' => ['X-XSRF-TOKEN' => $this->token]]);
 }
开发者ID:brbrown59,项目名称:bread-basket,代码行数:34,代码来源:listing-type-api-test.php


示例3: crypt

 public function crypt($password)
 {
     if (count($this->args) == 0) {
         $this->args[] = base64_encode(MWCryptRand::generate(16, true));
     }
     if (function_exists('hash_pbkdf2')) {
         $hash = hash_pbkdf2($this->params['algo'], $password, base64_decode($this->args[0]), (int) $this->params['rounds'], (int) $this->params['length'], true);
         if (!is_string($hash)) {
             throw new PasswordError('Error when hashing password.');
         }
     } else {
         $hashLenHash = hash($this->params['algo'], '', true);
         if (!is_string($hashLenHash)) {
             throw new PasswordError('Error when hashing password.');
         }
         $hashLen = strlen($hashLenHash);
         $blockCount = ceil($this->params['length'] / $hashLen);
         $hash = '';
         $salt = base64_decode($this->args[0]);
         for ($i = 1; $i <= $blockCount; ++$i) {
             $roundTotal = $lastRound = hash_hmac($this->params['algo'], $salt . pack('N', $i), $password, true);
             for ($j = 1; $j < $this->params['rounds']; ++$j) {
                 $lastRound = hash_hmac($this->params['algo'], $lastRound, $password, true);
                 $roundTotal ^= $lastRound;
             }
             $hash .= $roundTotal;
         }
         $hash = substr($hash, 0, $this->params['length']);
     }
     $this->hash = base64_encode($hash);
 }
开发者ID:kynikos,项目名称:archlinux-mediawiki,代码行数:31,代码来源:Pbkdf2Password.php


示例4: pbkdf2

 private function pbkdf2($algorithm, $password, $salt, $count, $key_length, $raw_output = false)
 {
     $algorithm = strtolower($algorithm);
     if (!in_array($algorithm, hash_algos(), true)) {
         trigger_error('PBKDF2 ERROR: Invalid hash algorithm.', E_USER_ERROR);
     }
     if ($count <= 0 || $key_length <= 0) {
         trigger_error('PBKDF2 ERROR: Invalid parameters.', E_USER_ERROR);
     }
     if (function_exists("hash_pbkdf2")) {
         if (!$raw_output) {
             $key_length = $key_length * 2;
         }
         return hash_pbkdf2($algorithm, $password, $salt, $count, $key_length, $raw_output);
     }
     $hash_length = strlen(hash($algorithm, "", true));
     $block_count = ceil($key_length / $hash_length);
     $output = "";
     for ($i = 1; $i <= $block_count; $i++) {
         $last = $salt . pack("N", $i);
         $last = $xorsum = hash_hmac($algorithm, $last, $password, true);
         for ($j = 1; $j < $count; $j++) {
             $xorsum ^= $last = hash_hmac($algorithm, $last, $password, true);
         }
         $output .= $xorsum;
     }
     if ($raw_output) {
         return substr($output, 0, $key_length);
     } else {
         return bin2hex(substr($output, 0, $key_length));
     }
 }
开发者ID:ThesisThesis,项目名称:tbookAPI,代码行数:32,代码来源:Hasher.php


示例5: __construct

 /**
  * Constructor.
  *
  * @param string $pass        The password.
  * @param string $key_length  Length of the derived key (in bytes).
  * @param array $opts         Additional options:
  *   - algo: (string) Hash algorithm.
  *   - i_count: (integer) Iteration count.
  *   - salt: (string) The salt to use.
  */
 public function __construct($pass, $key_length, array $opts = array())
 {
     $this->iterations = isset($opts['i_count']) ? $opts['i_count'] : 16384;
     if ($key_length <= 0 || $this->iterations <= 0) {
         throw new InvalidArgumentException('Invalid arguments');
     }
     $this->hashAlgo = isset($opts['algo']) ? $opts['algo'] : 'SHA256';
     /* Nice to have, but salt does not need to be cryptographically
      * secure random value. */
     $this->salt = isset($opts['salt']) ? $opts['salt'] : (function_exists('openssl_random_pseudo_bytes') ? openssl_random_pseudo_bytes($key_length) : substr(hash('sha512', new Horde_Support_Randomid(), true), 0, $key_length));
     if (function_exists('hash_pbkdf2')) {
         $this->_key = hash_pbkdf2($this->hashAlgo, $pass, $this->salt, $this->iterations, $key_length, true);
         return;
     }
     $hash_length = strlen(hash($this->hashAlgo, '', true));
     $block_count = ceil($key_length / $hash_length);
     $hash = '';
     for ($i = 1; $i <= $block_count; ++$i) {
         // $i encoded as 4 bytes, big endian.
         $last = $this->salt . pack('N', $i);
         for ($j = 0; $j < $this->iterations; $j++) {
             $last = hash_hmac($this->hashAlgo, $last, $pass, true);
             if ($j) {
                 $xorsum ^= $last;
             } else {
                 $xorsum = $last;
             }
         }
         $hash .= $xorsum;
     }
     $this->_key = substr($hash, 0, $key_length);
 }
开发者ID:horde,项目名称:horde,代码行数:42,代码来源:Pbkdf2.php


示例6: setUp

 /**
  * This setUp function creates user salt and user hash values for unit testing
  * @var string $VALID_USERSALT
  * @var string $VALID_USERHASH
  */
 public function setUp()
 {
     parent::setUp();
     $this->VALID_USERSALT = bin2hex(openssl_random_pseudo_bytes(32));
     $this->VALID_USERHASH = hash_pbkdf2("sha512", "iLoveIllinois", $this->VALID_USERSALT, 262144, 128);
     $this->VALID_CREATEDATE = DateTime::createFromFormat("Y-m-d H:i:s", $this->VALID_CREATEDATE);
 }
开发者ID:jmsaul,项目名称:open-trails,代码行数:12,代码来源:user-test.php


示例7: hashPass

function hashPass($salt, $pass)
{
    $iterations = 100;
    $length = 2048 / 8;
    //in bytes
    $hash = hash_pbkdf2("sha256", $pass, $salt, $iterations, $length * 2);
    return $hash;
}
开发者ID:zysicing,项目名称:CTFSys,代码行数:8,代码来源:utility.php


示例8: testPBKDF2

 public function testPBKDF2()
 {
     $mnemonic = "legal winner thank year wave sausage worth useful legal winner thank yellow";
     $passphrase = "TREZOR";
     $salt = "mnemonic{$passphrase}";
     $result = "2e8905819b8723fe2c1d161860e5ee1830318dbf49a83bd451cfb8440c28bd6fa457fe1296106559a3c80937a1c1069be3a3a5bd381ee6260e8d9739fce1f607";
     $this->assertEquals($result, hash_pbkdf2("sha512", $mnemonic, $salt, 2048, 64 * 2, false));
 }
开发者ID:NucleusStudios,项目名称:bitcoin-lib-php,代码行数:8,代码来源:BIP39Test.php


示例9: __construct

 /**
  * @param $key a per-site secret string which is used as the base encryption key.
  * @param $salt a per-session random string which is used as a salt to generate a per-session key
  *
  * The base encryption key needs to stay secret. If an attacker ever gets it, they can read their session,
  * and even modify & re-sign it.
  *
  * The salt is a random per-session string that is used with the base encryption key to create a per-session key.
  * This (amongst other things) makes sure an attacker can't use a known-plaintext attack to guess the key.
  *
  * Normally we could create a salt on encryption, send it to the client as part of the session (it doesn't
  * need to remain secret), then use the returned salt to decrypt. But we already have the Session ID which makes
  * a great salt, so no need to generate & handle another one.
  */
 public function __construct($key, $salt)
 {
     $this->ivSize = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC);
     $this->keySize = mcrypt_get_key_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC);
     $this->key = $key;
     $this->salt = $salt;
     $this->saltedkey = function_exists('hash_pbkdf2') ? hash_pbkdf2('sha256', $this->key, $this->salt, 1000, $this->keySize, true) : $this->hash_pbkdf2('sha256', $this->key, $this->salt, 100, $this->keySize);
 }
开发者ID:patricknelson,项目名称:silverstripe-hybridsessions,代码行数:22,代码来源:HybridSessionStore.php


示例10: setUp

 /**
  * create dependent objects before running each test
  */
 public final function setUp()
 {
     //run the default setUp() method first
     parent::setUp();
     //Generate Php 7 hash and salt //
     $password = "abc123";
     $this->salt = bin2hex(openssl_random_pseudo_bytes(32));
     $this->hash = hash_pbkdf2("sha512", $password, $this->salt, 262144, 128);
 }
开发者ID:chrispaul3625,项目名称:sprots,代码行数:12,代码来源:ProfileTest.php


示例11: createGID

 /**
  * Creates a GlobalID from a $key and $salt.
  * 
  * @param $key the publicKey
  * @param $salt the salt
  * 
  * @return the GlobalID
  */
 public static function createGID($key, $salt)
 {
     $gid = null;
     $key = PublicKey::exportKey($key);
     // headers, trailers, and linebreaks have to be deleted
     $gid = strtoupper(hash_pbkdf2(self::$HASH_ALGORITHM, $key, $salt, self::$ITERATIONS));
     $gid = self::convBase($gid, "0123456789ABCDEF", "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ");
     return $gid;
 }
开发者ID:sgoendoer,项目名称:sonic,代码行数:17,代码来源:GID.php


示例12: decrypt

 public static function decrypt($password, $secret, $encrypted_data)
 {
     //Generate a key by hashing the secret and password
     $key = hash_pbkdf2("sha256", $password, $secret, 1000, 32);
     //Split into data and iv
     list($encrypted_data, $iv) = explode('|', $encrypted_data);
     //Decrypt and return
     return openssl_decrypt($encrypted_data, 'aes-256-cbc', $key, 0, base64_decode($iv));
 }
开发者ID:d0x2f,项目名称:CaseFiles,代码行数:9,代码来源:Encryption.php


示例13: encodePassword

 /**
  * @param string $plainPassword
  * @param string $salt
  *
  * @return string
  *
  * @throws \InvalidArgumentException
  * @throws \LogicException when the algorithm is not supported
  */
 private function encodePassword($plainPassword, $salt)
 {
     Assert::lessThanEq(strlen($plainPassword), self::MAX_PASSWORD_LENGTH, sprintf('The password must be at most %d characters long.', self::MAX_PASSWORD_LENGTH));
     if (!in_array($this->algorithm, hash_algos(), true)) {
         throw new \LogicException(sprintf('The algorithm "%s" is not supported.', $this->algorithm));
     }
     $digest = hash_pbkdf2($this->algorithm, $plainPassword, $salt, $this->iterations, $this->length, true);
     return $this->encodeHashAsBase64 ? base64_encode($digest) : bin2hex($digest);
 }
开发者ID:loic425,项目名称:Sylius,代码行数:18,代码来源:UserPbkdf2PasswordEncoder.php


示例14: Get

 public static function Get($accountName, $password)
 {
     $account = AccountService::GetByName($accountName, true);
     if ($account->passwordkey == hash_pbkdf2("sha256", $password, $account->passwordsalt, 1000, 20)) {
         return $account;
     } else {
         return null;
     }
 }
开发者ID:krasaler,项目名称:FamilyStore,代码行数:9,代码来源:AccountService.php


示例15: makePassword

 public function makePassword($password)
 {
     $algorithm = "pbkdf2_sha256";
     $iterations = 12000;
     $newSalt = mcrypt_create_iv(6, MCRYPT_DEV_URANDOM);
     $newSalt = base64_encode($newSalt);
     $hash = hash_pbkdf2("SHA256", $password, $newSalt, $iterations, 0, true);
     $toDBStr = $algorithm . "\$" . $iterations . "\$" . $newSalt . "\$" . base64_encode($hash);
     return $toDBStr;
 }
开发者ID:Resmin,项目名称:Resmin-Api,代码行数:10,代码来源:AuthService.php


示例16: updateSubUserPassword

 public function updateSubUserPassword($newPassword)
 {
     if ($this->validated) {
         $newSalt = bin2hex(mcrypt_create_iv(_PASSWORD_SALT_IV_SIZE_, MCRYPT_DEV_URANDOM));
         $newPassword = hash_pbkdf2('sha512', $newPassword, $newSalt, 1000);
         AuthUserData::updatePasswordAndSalt($this->userID, $newPassword, $newSalt);
         return true;
     }
     return false;
 }
开发者ID:rapidDevGroup,项目名称:PHP-REST-API,代码行数:10,代码来源:AuthSubUser.php


示例17: getDerivedKey

 /**
  * Encode and get derived key
  *
  * @param string $key
  * @param string $salt
  * @param int $iterations
  * @param int $keyLen
  * @return string
  */
 public static function getDerivedKey($key, $salt, $iterations = 1000, $keyLen = 32)
 {
     if (function_exists("hash_pbkdf2")) {
         $key = hash_pbkdf2('sha256', $key, $salt, $iterations, $keyLen, true);
     } else {
         // PHP v5.4 compatibility
         $key = static::compat_pbkdf2('sha256', $key, $salt, $iterations, $keyLen, true);
     }
     return base64_encode($key);
 }
开发者ID:voryx,项目名称:thruway,代码行数:19,代码来源:Utils.php


示例18: aes_decrypt

function aes_decrypt($data, $password)
{
    $salt = substr($data, 0, SALT_LEN);
    $data = substr($data, SALT_LEN);
    $decrypted = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, hash_pbkdf2(KEY_ALGO, $password, $salt, ITERATIONS, KEY_LENGTH, true), base64_decode($data), MCRYPT_MODE_CBC, str_repeat(chr(0), 16));
    // Strip padding out.
    $block = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
    $pad = ord($decrypted[strlen($decrypted) - 1]);
    return substr($decrypted, 0, strlen($decrypted) - $pad);
}
开发者ID:LEECHIENKUAN,项目名称:aes_pbkdf2,代码行数:10,代码来源:aes_pbkdf2.php


示例19: encodePassword

 /**
  * @param string $plainPassword
  * @param string $salt
  *
  * @return string
  *
  * @throws \LogicException when the algorithm is not supported
  */
 protected function encodePassword($plainPassword, $salt)
 {
     if ($this->isPasswordTooLong($plainPassword)) {
         throw new \InvalidArgumentException('Too long password.');
     }
     if (!in_array($this->algorithm, hash_algos(), true)) {
         throw new \LogicException(sprintf('The algorithm "%s" is not supported.', $this->algorithm));
     }
     $digest = hash_pbkdf2($this->algorithm, $plainPassword, $salt, $this->iterations, $this->length, true);
     return $this->encodeHashAsBase64 ? base64_encode($digest) : bin2hex($digest);
 }
开发者ID:aleherse,项目名称:Sylius,代码行数:19,代码来源:UserPbkdf2PasswordEncoder.php


示例20: passgen

function passgen($password, $salt, $raw = false, $len = 32, $iterations = 500000)
{
    //$salt = mcrypt_create_iv(16);
    $hash = hash_pbkdf2("sha256", $password, $salt, $iterations, $len);
    $hash_array = str_split($hash, 2);
    $hash_chr = null;
    for ($i = 0; $i < count($hash_array); $i++) {
        $hash_chr .= chr('0x' . $hash_array[$i]);
    }
    return $raw ? $hash_chr : base64_encode($hash_chr);
}
开发者ID:hartmantam,项目名称:php-license-system,代码行数:11,代码来源:passwordGenerator.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP hash_rand函数代码示例发布时间:2022-05-15
下一篇:
PHP hash_password函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap