{"size": 646, "ext": "js", "max_stars_repo_path": "app/proxy/smon_decryptor.js", "max_stars_repo_name": "A1Darkwing/sw-rta-exporter", "max_stars_repo_stars_event_min_datetime": "2020-05-20T09:34:27.000Z", "max_stars_repo_stars_event_max_datetime": "2020-05-20T09:34:27.000Z", "max_issues_repo_path": "app/proxy/smon_decryptor.js", "max_issues_repo_name": "A1Darkwing/sw-rta-exporter", "max_issues_repo_issues_event_min_datetime": "2022-03-25T19:17:50.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-25T19:17:50.000Z", "max_forks_repo_path": "app/proxy/smon_decryptor.js", "max_forks_repo_name": "A1Darkwing/sw-rta-exporter", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": 1, "max_forks_count": null, "avg_line_length": 30.7619047619, "max_line_length": 125, "alphanum_fraction": 0.6950464396}
const crypto = require('crypto');
const zlib = require('zlib');

const encryptkey = require(`./binaries/key-${process.platform}-${process.arch}`);

function decrypt(text) {
  const key = encryptkey.key();
  const algorithm = 'aes-128-cbc';

  let decipher = crypto.createDecipheriv(algorithm, key, '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00');
  let dec = decipher.update(text, 'base64', 'latin1');
  dec += decipher.final('latin1');

  return dec;
}

module.exports = {
  decrypt_request: text => JSON.parse(decrypt(text)),
  decrypt_response: text => JSON.parse(zlib.inflateSync(Buffer.from(decrypt(text), 'latin1')))
};
