2013-04-02 09:02:57 -04:00
|
|
|
/**
|
2013-05-14 06:01:51 -04:00
|
|
|
* A Wrapper for Forge's PBKDF2 function
|
2013-04-02 09:02:57 -04:00
|
|
|
*/
|
2013-06-10 17:07:29 -04:00
|
|
|
define(['forge'], function(forge) {
|
2013-04-01 18:12:15 -04:00
|
|
|
'use strict';
|
2013-03-13 11:58:46 -04:00
|
|
|
|
2013-06-10 17:07:29 -04:00
|
|
|
var self = {};
|
|
|
|
|
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-06-10 17:07:29 -04:00
|
|
|
self.getKey = function(password, keySize) {
|
2013-05-14 06:01:51 -04:00
|
|
|
var salt = forge.util.decode64("vbhmLjC+Ub6MSbhS6/CkOwxB25wvwRkSLP2DzDtYb+4=");
|
|
|
|
var key = forge.pkcs5.pbkdf2(password, salt, 1000, keySize / 8);
|
|
|
|
var keyBase64 = forge.util.encode64(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-06-10 17:07:29 -04:00
|
|
|
return self;
|
|
|
|
});
|