-
-
Save acgotaku/091a7a5d181b3211392b0fbdaf37d347 to your computer and use it in GitHub Desktop.
EncryptRule
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const crypto = require('crypto'); | |
const mac = '00226e2fc269'; | |
const model = 'EVPAD-6P'; | |
const real_mac = '62a6fbce3641'; | |
const real_model = 'ONEPLUS A5000'; | |
function md5hex(str) { | |
const md5 = crypto.createHash('md5'); | |
return md5.update(str, 'binary').digest('hex'); | |
} | |
function getAlgorithm(keyBase64) { | |
const key = Buffer.from(keyBase64, 'utf8'); | |
switch (key.length) { | |
case 16: | |
return 'aes-128-cbc'; | |
case 32: | |
return 'aes-256-cbc'; | |
} | |
throw new Error('Invalid key length: ' + key.length); | |
} | |
function encrypt(plainText, keyBase64, ivBase64) { | |
const key = Buffer.from(keyBase64, 'utf8'); | |
const iv = Buffer.from(ivBase64, 'utf8'); | |
const cipher = crypto.createCipheriv(getAlgorithm(keyBase64), key, iv); | |
let encrypted = cipher.update(plainText, 'utf8', 'base64'); | |
encrypted += cipher.final('base64'); | |
return encrypted; | |
} | |
function decrypt(messagebase64, keyBase64, ivBase64) { | |
const key = Buffer.from(keyBase64, 'utf8'); | |
const iv = Buffer.from(ivBase64, 'utf8'); | |
const decipher = crypto.createDecipheriv(getAlgorithm(keyBase64), key, iv); | |
let decrypted = decipher.update(messagebase64, 'base64'); | |
decrypted += decipher.final(); | |
return decrypted; | |
} | |
function getSoDecrypKey(macAddr = mac, modelName = model) { | |
return md5hex(macAddr.substring(4, 10) + '036014a5' + modelName).substring(8, 24); | |
} | |
function getSoEncrypKey(macAddr = mac, time) { | |
return md5hex(macAddr.substring(4, 10) + '036014a5' + time).substring(8, 24); | |
} | |
function getSoEncrypDevKey(time) { | |
const table = '0123456789ABCDEF'; | |
const result = new Array(32); | |
const len = time.length; | |
for (let i = 0; i < 32; i++) { | |
const key = i % len; | |
const index = Number(time[key]) + i; | |
result[i] = table[index % 16]; | |
} | |
return result.join(''); | |
} | |
console.log('fake dec key:', getSoDecrypKey(mac, model)); | |
console.log('real dec key:', getSoDecrypKey(real_mac, real_model)); | |
const utctime = '1670638443934'; | |
console.log('fake enc key:', getSoEncrypKey(mac, utctime)); | |
console.log('real enc key:', getSoEncrypKey(real_mac, utctime)); | |
const rawKey = getSoEncrypDevKey(utctime); | |
console.log('enc dev key:', rawKey.substring(0, 8) + rawKey.slice(-8)); | |
console.log('enc dev iv:', rawKey.substring(8, 24)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
说起来不换 esm 么?都 2202 年了(