1
0
mirror of https://github.com/moparisthebest/mail synced 2024-11-16 22:25:08 -05:00
mail/src/js/crypto/aes-worker.js

35 lines
899 B
JavaScript
Raw Normal View History

(function() {
'use strict';
// import web worker dependencies
importScripts('../../lib/forge/forge.rsa.bundle.js');
importScripts('../app-config.js');
importScripts('./aes-cbc.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) {
var i = e.data,
2013-03-13 11:58:46 -04:00
output = null,
aes = new cryptoLib.AesCBC(forge);
if (i.type === 'encrypt' && i.plaintext && i.key && i.iv) {
2013-03-13 11:58:46 -04:00
// start encryption
output = aes.encrypt(i.plaintext, i.key, i.iv);
} else if (i.type === 'decrypt' && i.ciphertext && i.key && i.iv) {
2013-03-13 11:58:46 -04:00
// start decryption
output = aes.decrypt(i.ciphertext, i.key, i.iv);
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(output);
2013-04-10 11:14:19 -04:00
};
2013-03-13 11:58:46 -04:00
}());