2013-04-02 09:02:57 -04:00
|
|
|
/**
|
|
|
|
* A Wrapper for Crypto.js's PBKDF2 function
|
|
|
|
*/
|
|
|
|
app.crypto.PBKDF2 = function() {
|
2013-04-01 18:12:15 -04:00
|
|
|
'use strict';
|
2013-03-13 11:58:46 -04:00
|
|
|
|
|
|
|
/**
|
2013-04-02 09:02:57 -04:00
|
|
|
* PBKDF2-HMAC-SHA1 key derivation with a constant salt and 1000 iterations
|
|
|
|
* @param password [String] The password in UTF8
|
|
|
|
* @param keySize [Number] The key size in bits
|
|
|
|
* @return [String] The base64 encoded key
|
2013-03-13 11:58:46 -04:00
|
|
|
*/
|
2013-04-02 09:02:57 -04:00
|
|
|
this.getKey = function(password, keySize) {
|
|
|
|
var salt = CryptoJS.enc.Base64.parse("vbhmLjC+Ub6MSbhS6/CkOwxB25wvwRkSLP2DzDtYb+4="); // from random 256 bit value
|
|
|
|
var key = CryptoJS.PBKDF2(password, salt, {
|
|
|
|
keySize: keySize / 32,
|
|
|
|
iterations: 1000
|
|
|
|
});
|
|
|
|
var keyBase64 = CryptoJS.enc.Base64.stringify(key);
|
2013-04-01 18:12:15 -04:00
|
|
|
|
2013-04-02 09:02:57 -04:00
|
|
|
return keyBase64;
|
2013-03-13 11:58:46 -04:00
|
|
|
};
|
2013-04-01 18:12:15 -04:00
|
|
|
|
2013-04-02 09:02:57 -04:00
|
|
|
};
|