var exec = require('child_process').exec;
var fs = require('fs');
var temp = require('temp');

module.exports = function (options, data, key, callback) {
    var tmpFile = temp.path();
    var cmdline = options.opensslPath + ' rsautl';

    cmdline += ' -' + options.operation;
    cmdline += ' -' + options.padding;
    cmdline += ' -inkey ' + tmpFile;

    if (options.operation === 'encrypt' || options.operation === 'verify') {
        cmdline += ' -pubin';
    }

    fs.writeFile(tmpFile, key, function (err) {
        if (err) throw err;

        var execOpts = { encoding: 'utf8' };
        if (options.operation === 'encrypt' || options.operation === 'sign') {
            execOpts.encoding = 'base64';
        }

        var proc = exec(cmdline, execOpts, function (err, stdout, stderr) {
            if (err) throw err;

            callback(null, stdout);
            fs.unlink(tmpFile);
        });

        if (options.operation === 'decrypt' || options.operation === 'verify') {
            proc.stdin.write(new Buffer(data, 'base64'));
        } else {
            proc.stdin.write(data);
        }

        proc.stdin.end();
    });
};

@@ -523,34 +523,101 @@
    if (err) 
-throw err;
+%7B%0A            fs.unlink(tmpFile);%0A            return callback(err);%0A        %7D
 %0A%0A        va
@@ -884,18 +884,97 @@
 rr) 
-throw err;
+%7B%0A                fs.unlink(tmpFile);%0A                return callback(err);%0A            %7D
 %0A%0A  

Remove temp files on errors