mail/src/js/crypto/pbkdf2-worker.js

35 lines
929 B
JavaScript
Raw Normal View History

(function() {
'use strict';
2013-03-13 11:58:46 -04:00
// import web worker dependencies
importScripts('../../lib/crypto-js/core.js');
importScripts('../../lib/crypto-js/enc-base64.js');
importScripts('../../lib/crypto-js/sha1.js');
importScripts('../../lib/crypto-js/hmac.js');
importScripts('../../lib/crypto-js/pbkdf2.js');
importScripts('../app-config.js');
importScripts('./pbkdf2.js');
2013-03-13 11:58:46 -04:00
/**
* In the web worker thread context, 'this' and 'self' can be used as a global
* variable namespace similar to the 'window' object in the main thread
*/
2013-04-10 11:14:19 -04:00
self.onmessage = function(e) {
2013-03-13 11:58:46 -04:00
var args = e.data,
key = null;
2013-03-13 11:58:46 -04:00
if (e.data.password && e.data.keySize) {
// start deriving key
var pbkdf2 = new app.crypto.PBKDF2();
key = pbkdf2.getKey(e.data.password, e.data.keySize);
2013-03-13 11:58:46 -04:00
} else {
throw 'Not all arguments for web worker crypto are defined!';
}
2013-03-13 11:58:46 -04:00
// pass output back to main thread
self.postMessage(key);
2013-04-10 11:14:19 -04:00
};
2013-03-13 11:58:46 -04:00
}());