const config = require('./config');
const crypto = require("crypto");
var ENCRYPTION_KEY=config.ENCRYPTION_KEY;

function check_headers(req){
    if(config.headers.username == req.header('X-username') && config.headers.password == req.header('X-password')){
        return "True"
    }else{
        return "False";
    }
}

function encrypt(text) {
    var cipher = crypto.createCipher('aes256',ENCRYPTION_KEY);  
    var encrypted = cipher.update(text, 'utf8', 'hex') + cipher.final('hex'); 
    return(encrypted);
}

function decrypt(text) {
    var decipher = crypto.createDecipher('aes256',ENCRYPTION_KEY);
    var decrypted = decipher.update(text, 'hex', 'utf8') + decipher.final('utf8');
    return(decrypted);
}
function sleep(ms) {
    return new Promise(resolve => setTimeout(resolve, ms));
  }

module.exports = {
    check_headers,encrypt,decrypt,sleep
}