;(function (root, factory, undef) { if (typeof exports === "object") { // CommonJS module.exports = exports = factory(require("./core"), require("./sha1"), require("./hmac")); } else if (typeof define === "function" && define.amd) { // AMD define(["./core", "./sha1", "./hmac"], factory); } else { // Global (browser) factory(root.CryptoJS); } }(this, function (CryptoJS) { (function () { // Shortcuts var C = CryptoJS; var C_lib = C.lib; var Base = C_lib.Base; var WordArray = C_lib.WordArray; var C_algo = C.algo; var SHA1 = C_algo.SHA1; var HMAC = C_algo.HMAC; /** * Password-Based Key Derivation Function 2 algorithm. */ var PBKDF2 = C_algo.PBKDF2 = Base.extend({ /** * Configuration options. * * @property {number} keySize The key size in words to generate. Default: 4 (128 bits) * @property {Hasher} hasher The hasher to use. Default: SHA1 * @property {number} iterations The number of iterations to perform. Default: 1 */ cfg: Base.extend({ keySize: 128/32, hasher: SHA1, iterations: 1 }), /** * Initializes a newly created key derivation function. * * @param {Object} cfg (Optional) The configuration options to use for the derivation. * * @example * * var kdf = CryptoJS.algo.PBKDF2.create(); * var kdf = CryptoJS.algo.PBKDF2.create({ keySize: 8 }); * var kdf = CryptoJS.algo.PBKDF2.create({ keySize: 8, iterations: 1000 }); */ init: function (cfg) { this.cfg = this.cfg.extend(cfg); }, /** * Computes the Password-Based Key Derivation Function 2. * * @param {WordArray|string} password The password. * @param {WordArray|string} salt A salt. * * @return {WordArray} The derived key. * * @example * * var key = kdf.compute(password, salt); */ compute: function (password, salt) { // Shortcut var cfg = this.cfg; // Init HMAC var hmac = HMAC.create(cfg.hasher, password); // Initial values var derivedKey = WordArray.create(); var blockIndex = WordArray.create([0x00000001]); // Shortcuts var derivedKeyWords = derivedKey.words; var blockIndexWords = blockIndex.words; var keySize = cfg.keySize; var iterations = cfg.iterations; // Generate key while (derivedKeyWords.length < keySize) { var block = hmac.update(salt).finalize(blockIndex); hmac.reset(); // Shortcuts var blockWords = block.words; var blockWordsLength = blockWords.length; // Iterations var intermediate = block; for (var i = 1; i < iterations; i++) { intermediate = hmac.finalize(intermediate); hmac.reset(); // Shortcut var intermediateWords = intermediate.words; // XOR intermediate with block for (var j = 0; j < blockWordsLength; j++) { blockWords[j] ^= intermediateWords[j]; } } derivedKey.concat(block); blockIndexWords[0]++; } derivedKey.sigBytes = keySize * 4; return derivedKey; } }); /** * Computes the Password-Based Key Derivation Function 2. * * @param {WordArray|string} password The password. * @param {WordArray|string} salt A salt. * @param {Object} cfg (Optional) The configuration options to use for this computation. * * @return {WordArray} The derived key. * * @static * * @example * * var key = CryptoJS.PBKDF2(password, salt); * var key = CryptoJS.PBKDF2(password, salt, { keySize: 8 }); * var key = CryptoJS.PBKDF2(password, salt, { keySize: 8, iterations: 1000 }); */ C.PBKDF2 = function (password, salt, cfg) { return PBKDF2.create(cfg).compute(password, salt); }; }()); return CryptoJS.PBKDF2; }));
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
docs | Folder | 0755 |
|
|
CONTRIBUTING.md | File | 482 B | 0644 |
|
LICENSE | File | 1.14 KB | 0644 |
|
README.md | File | 5.74 KB | 0644 |
|
aes.js | File | 8.45 KB | 0644 |
|
bower.json | File | 645 B | 0644 |
|
cipher-core.js | File | 28.96 KB | 0644 |
|
core.js | File | 23.08 KB | 0644 |
|
crypto-js.js | File | 193.47 KB | 0644 |
|
enc-base64.js | File | 3.99 KB | 0644 |
|
enc-base64url.js | File | 4.33 KB | 0644 |
|
enc-hex.js | File | 359 B | 0644 |
|
enc-latin1.js | File | 362 B | 0644 |
|
enc-utf16.js | File | 3.99 KB | 0644 |
|
enc-utf8.js | File | 360 B | 0644 |
|
evpkdf.js | File | 3.9 KB | 0644 |
|
format-hex.js | File | 1.78 KB | 0644 |
|
format-openssl.js | File | 416 B | 0644 |
|
hmac-md5.js | File | 422 B | 0644 |
|
hmac-ripemd160.js | File | 440 B | 0644 |
|
hmac-sha1.js | File | 425 B | 0644 |
|
hmac-sha224.js | File | 464 B | 0644 |
|
hmac-sha256.js | File | 431 B | 0644 |
|
hmac-sha3.js | File | 462 B | 0644 |
|
hmac-sha384.js | File | 501 B | 0644 |
|
hmac-sha512.js | File | 468 B | 0644 |
|
hmac.js | File | 3.89 KB | 0644 |
|
index.js | File | 1.59 KB | 0644 |
|
lib-typedarrays.js | File | 2.18 KB | 0644 |
|
md5.js | File | 9.2 KB | 0644 |
|
mode-cfb.js | File | 2.07 KB | 0644 |
|
mode-ctr-gladman.js | File | 2.28 KB | 0644 |
|
mode-ctr.js | File | 1.43 KB | 0644 |
|
mode-ecb.js | File | 893 B | 0644 |
|
mode-ofb.js | File | 1.3 KB | 0644 |
|
package.json | File | 719 B | 0644 |
|
pad-ansix923.js | File | 1.24 KB | 0644 |
|
pad-iso10126.js | File | 1.09 KB | 0644 |
|
pad-iso97971.js | File | 918 B | 0644 |
|
pad-nopadding.js | File | 554 B | 0644 |
|
pad-pkcs7.js | File | 411 B | 0644 |
|
pad-zeropadding.js | File | 1.08 KB | 0644 |
|
pbkdf2.js | File | 4.43 KB | 0644 |
|
rabbit-legacy.js | File | 6.56 KB | 0644 |
|
rabbit.js | File | 6.52 KB | 0644 |
|
rc4.js | File | 3.49 KB | 0644 |
|
ripemd160.js | File | 9.17 KB | 0644 |
|
sha1.js | File | 3.97 KB | 0644 |
|
sha224.js | File | 1.87 KB | 0644 |
|
sha256.js | File | 5.41 KB | 0644 |
|
sha3.js | File | 10.4 KB | 0644 |
|
sha384.js | File | 2.21 KB | 0644 |
|
sha512.js | File | 13.15 KB | 0644 |
|
tripledes.js | File | 24.29 KB | 0644 |
|
x64-core.js | File | 8.68 KB | 0644 |
|