Skip to content

Instantly share code, notes, and snippets.

@acgotaku

acgotaku/aes.js Secret

Last active December 27, 2022 12:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save acgotaku/091a7a5d181b3211392b0fbdaf37d347 to your computer and use it in GitHub Desktop.
Save acgotaku/091a7a5d181b3211392b0fbdaf37d347 to your computer and use it in GitHub Desktop.
EncryptRule
'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));
@acgotaku
Copy link
Author

只是个逆向脚本而已,怎么简单怎么来

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment