Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict'
- const crc = require('crc')
- const zlib = require('zlib')
- const crypto = require('crypto')
- const AES_SECRET = 'eagleye_9fd&fwfl'
- class EagleEye {
- static hexToBytes (hex) {
- for (var bytes = [], c = 0; c < hex.length; c += 2) { bytes.push(parseInt(hex.substr(c, 2), 16)) }
- return bytes
- }
- static bytesToHex (bytes) {
- for (var hex = [], i = 0; i < bytes.length; i++) {
- hex.push((bytes[i] >>> 4).toString(16))
- hex.push((bytes[i] & 0xF).toString(16))
- }
- return hex.join('')
- }
- static encrypt (payload) {
- var key128 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
- var iv = Buffer.from(key128)
- let key = Buffer.from(AES_SECRET)
- let cipher = crypto.createCipheriv('aes-128-cfb', key, iv)
- cipher.setAutoPadding(false)
- let encrypted = cipher.update(payload)
- return encrypted
- }
- static decrypt (hex) {
- var key128 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
- var iv = Buffer.from(key128)
- let key = Buffer.from(AES_SECRET)
- let decipher = crypto.createDecipheriv('aes-128-cfb', key, iv)
- decipher.setAutoPadding(false)
- var deciphered = decipher.update(hex)
- decipher.final()
- return deciphered.toString('utf8')
- }
- static encode (pl) {
- let str = this.encrypt(pl)
- let woo = this.bytesToHex(str)
- let hash = crc.crc32(woo.toString())
- woo = woo + ',' + hash
- let output = zlib.gzipSync(Buffer.from(woo))
- return output
- }
- static decode (hexString) {
- var output = zlib.gunzipSync(Buffer.from(hexString, 'hex'))
- let woo = this.hexToBytes(output.toString().split(',')[0])
- let out = EagleEye.decrypt(Buffer.from(woo))
- return out.toString()
- }
- }
- module.exports = EagleEye
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement