Advertisement
Guest User

Untitled

a guest
Jul 3rd, 2020
750
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'use strict'
  2.  
  3. const crc = require('crc')
  4. const zlib = require('zlib')
  5. const crypto = require('crypto')
  6.  
  7. const AES_SECRET = 'eagleye_9fd&fwfl'
  8.  
  9. class EagleEye {
  10.   static hexToBytes (hex) {
  11.     for (var bytes = [], c = 0; c < hex.length; c += 2) { bytes.push(parseInt(hex.substr(c, 2), 16)) }
  12.     return bytes
  13.   }
  14.  
  15.   static bytesToHex (bytes) {
  16.     for (var hex = [], i = 0; i < bytes.length; i++) {
  17.       hex.push((bytes[i] >>> 4).toString(16))
  18.       hex.push((bytes[i] & 0xF).toString(16))
  19.     }
  20.     return hex.join('')
  21.   }
  22.  
  23.   static encrypt (payload) {
  24.     var key128 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
  25.     var iv = Buffer.from(key128)
  26.     let key = Buffer.from(AES_SECRET)
  27.     let cipher = crypto.createCipheriv('aes-128-cfb', key, iv)
  28.     cipher.setAutoPadding(false)
  29.     let encrypted = cipher.update(payload)
  30.     return encrypted
  31.   }
  32.  
  33.   static decrypt (hex) {
  34.     var key128 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
  35.     var iv = Buffer.from(key128)
  36.     let key = Buffer.from(AES_SECRET)
  37.     let decipher = crypto.createDecipheriv('aes-128-cfb', key, iv)
  38.     decipher.setAutoPadding(false)
  39.     var deciphered = decipher.update(hex)
  40.     decipher.final()
  41.     return deciphered.toString('utf8')
  42.   }
  43.  
  44.   static encode (pl) {
  45.     let str = this.encrypt(pl)
  46.     let woo = this.bytesToHex(str)
  47.     let hash = crc.crc32(woo.toString())
  48.     woo = woo + ',' + hash
  49.     let output = zlib.gzipSync(Buffer.from(woo))
  50.     return output
  51.   }
  52.  
  53.   static decode (hexString) {
  54.     var output = zlib.gunzipSync(Buffer.from(hexString, 'hex'))
  55.     let woo = this.hexToBytes(output.toString().split(',')[0])
  56.     let out = EagleEye.decrypt(Buffer.from(woo))
  57.     return out.toString()
  58.   }
  59. }
  60.  
  61. module.exports = EagleEye
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement