1
0
mirror of https://github.com/moparisthebest/mail synced 2024-11-12 04:05:13 -05:00
mail/src/js/crypto/pbkdf2.js

24 lines
629 B
JavaScript
Raw Normal View History

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) {
'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-02 09:02:57 -04:00
return keyBase64;
2013-03-13 11:58:46 -04:00
};
2013-06-10 17:07:29 -04:00
return self;
});