1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- (function(){
- var util = Crypto.util;
- Crypto.PBKDF2 = function (password, salt, keylen, options) {
-
- var hasher = options && options.hasher || Crypto.SHA1,
- iterations = options && options.iterations || 1;
-
- function PRF(password, salt) {
- return Crypto.HMAC(hasher, salt, password, { asBytes: true });
- }
-
- var derivedKeyBytes = [],
- blockindex = 1;
- while (derivedKeyBytes.length < keylen) {
- var block = PRF(password, salt + util.bytesToString(
- util.wordsToBytes([blockindex])));
- for (var u = block, i = 1; i < iterations; i++) {
- u = PRF(password, util.bytesToString(u));
- for (var j = 0; j < block.length; j++) block[j] ^= u[j];
- }
- derivedKeyBytes = derivedKeyBytes.concat(block);
- blockindex++;
- }
-
- derivedKeyBytes.length = keylen;
- return options && options.asBytes ? derivedKeyBytes :
- options && options.asString ? util.bytesToString(derivedKeyBytes) :
- util.bytesToHex(derivedKeyBytes);
- };
- })();
|