{"size": 852, "ext": "js", "max_stars_repo_path": "app/middlewares/RSADecryption.js", "max_stars_repo_name": "soofyhbk2007/Jarvis_System", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "app/middlewares/RSADecryption.js", "max_issues_repo_name": "soofyhbk2007/Jarvis_System", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "app/middlewares/RSADecryption.js", "max_forks_repo_name": "soofyhbk2007/Jarvis_System", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 29.3793103448, "max_line_length": 71, "alphanum_fraction": 0.529342723}
var cryptico = require('cryptico');
var rsa_pr = cryptico.generateRSAKey(process.env.RSA_PASSWORD, 1024);
var rsa_pu = cryptico.publicKeyString(rsa_pr);
process.env.RSA_PU = rsa_pu;

module.exports = function(req, res, next) {
    if (req.body.body) {
        req.body = req.body.body;

        try {
            var body = req.body;
            var decrypted = cryptico.decrypt(body, rsa_pr);
            req.body = JSON.parse(decrypted.plaintext);
            next();
        } catch (error) {
            res.status(400).json({
               status:'failed',
               message: 'The request body is not in the right format.'
            });
        }
    }
    else {
        res.status(400).json({
           status:'failed',
           message: 'The request body is not in the right format.'
        });
    }
};
