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

25 lines
607 B
JavaScript
Raw Normal View History

2014-10-02 16:05:44 -04:00
'use strict';
2013-03-13 11:58:46 -04:00
2014-10-08 12:36:00 -04:00
importScripts('forge.min.js');
2014-10-02 16:05:44 -04:00
var pbkdf2 = require('./pbkdf2');
2013-03-13 11:58:46 -04:00
2014-10-02 16:05:44 -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
*/
self.onmessage = function(e) {
var i = e.data,
key = null;
2014-10-02 16:05:44 -04:00
if (i.password && i.salt && i.keySize) {
// start deriving key
key = pbkdf2.getKey(i.password, i.salt, i.keySize);
2014-10-02 16:05:44 -04:00
} else {
throw 'Not all arguments for web worker crypto are defined!';
}
2014-10-02 16:05:44 -04:00
// pass output back to main thread
self.postMessage(key);
};