Hej,
Robię sobie port kodu z pythona w node.js
Trochę utknąłem na fragmencie z dekodowaniem danych, tu źródełko na którym się opieram:
https://github.com/mac-zhou/midea-msmart/blob/master/msmart/security.py
Tu mój kod:
import md5 from "md5-crypto";
import crypto from "crypto";
const appKey = "434a209a5ce141c3b726de067835d7f0";
const signKey = "xhdiwjnchekd4d512chdjx5d8e4c394D2D7S";
const blockSize = 16;
const encKey = md5(signKey);
const dynamicKey = md5(appKey).substring(0, 16);
console.log({ encKey, dynamicKey });
const decrypt = (data: Buffer) => {
console.log(
"gonna decrypt", data.toString("hex"), data.length,
"with key", Buffer.from(encKey, "hex"), Buffer.from(encKey, "hex").length);
const decipher = crypto.createDecipher(
"aes-128-ecb", Buffer.from(encKey, "hex"),
);
// decipher.setAutoPadding(false)
decipher.update(data);
const r = decipher.final();
console.log("got", r.length);
return "aaa";
};
a to dane, które próbuję zdekodować:
02e116ff85a695ea10924e785d841509ec476b78946ceec89abee5114c2ddd597d1f1ba7ce12ca33e00198b12fe24a02143a85a50e7db494e81191393f3425860c27da48caed02dd6f6b8206f2a056101fca94541303884c52e880ddefc03190f31443d17c3aac03a7656614ae1dca44
czyli przykład użycia
decode(Buffer.from("02e116ff85a695ea10924e785d841509ec476b78946ceec89abee5114c2ddd597d1f1ba7ce12ca33e00198b12fe24a02143a85a50e7db494e81191393f3425860c27da48caed02dd6f6b8206f2a056101fca94541303884c52e880ddefc03190f31443d17c3aac03a7656614ae1dca44", "hex"));
niestety - nie dostaję żadnego sensownego rezultatu tylko:
Error: error:06065064:digital envelope routines:EVP_DecryptFinal_ex:bad decrypt
Co robię źle?