chat-client/tasks.js

48 lines
1.0 KiB
JavaScript

// Include some libraries
const node_rsa = require("node-rsa");
module.exports = function(args, callback)
{
// Does the main task want an rsa key
if(args["mode"] == "make_rsa_key")
{
// Make an rsa key with the specified size
var key = new node_rsa({b:args['size']});
// Get the public and private keys
var data = {
public: key.exportKey("public"),
private: key.exportKey("private")
}
// Send it back to the main task
callback(data);
}
// Does the main task want to decode something
else if(args["mode"] == "decrypt_rsa")
{
// Load the key
var key = new node_rsa();
key.importKey(args["public"], "public");
key.importKey(args["private"], "private");
// Decode the data
var data = key.decrypt(args["string"]);
// Send it back to the main task
callback({
out: data.toString(),
public: key.exportKey("public"),
private: key.exportKey("private")
});
}
else
{
// Call back nothing
callback(undefined);
}
}