cscg24-guacamole

CSCG 2024 Challenge 'Guacamole Mashup'
git clone https://git.sinitax.com/sinitax/cscg24-guacamole
Log | Files | Refs | sfeed.txt

Crypt.js (815B)


      1const Crypto = require('crypto');
      2
      3class Crypt {
      4
      5    constructor(app) {
      6        this.server = app;
      7    }
      8
      9    decrypt(encodedString) {
     10        let encoded = JSON.parse(this.constructor.base64decode(encodedString));
     11
     12        encoded.iv = this.constructor.base64decode(encoded.iv);
     13        encoded.value = this.constructor.base64decode(encoded.value, 'binary');
     14
     15        const decipher = Crypto.createDecipheriv(this.server.clientOptions.crypt.cypher, this.server.clientOptions.crypt.key, encoded.iv);
     16
     17        let decrypted = decipher.update(encoded.value, 'binary', 'ascii');
     18        decrypted += decipher.final('ascii');
     19
     20        return JSON.parse(decrypted);
     21    }
     22
     23    static base64decode(string, mode) {
     24        return Buffer.from(string, 'base64').toString(mode || 'ascii');
     25    }
     26
     27}
     28
     29module.exports = Crypt;