UNPKG

matterbridge-roborock-vacuum-plugin

Version:
24 lines (23 loc) 878 B
import crypto from 'node:crypto'; export function md5bin(str) { return crypto.createHash('md5').update(str).digest(); } export function md5hex(str) { return crypto.createHash('md5').update(str).digest('hex'); } export function decryptECB(encrypted, aesKey) { const decipher = crypto.createDecipheriv('aes-128-ecb', aesKey, null); decipher.setAutoPadding(false); let decrypted = decipher.update(encrypted, 'binary', 'utf8'); decrypted += decipher.final('utf8'); return removePadding(decrypted); } function removePadding(str) { const paddingLength = str.charCodeAt(str.length - 1); return str.slice(0, -paddingLength); } export const SALT = 'TXdfu$jyZ#TZHsg4'; export function encodeTimestamp(timestamp) { const hex = timestamp.toString(16).padStart(8, '0').split(''); return [5, 6, 3, 7, 1, 2, 0, 4].map((idx) => hex[idx]).join(''); }