29 lines
845 B
JavaScript
29 lines
845 B
JavaScript
"use strict";
|
|
|
|
import aes from 'aes-js';
|
|
|
|
const offset_id = 0;
|
|
const offset_lat = 32 / 8;
|
|
const offset_lng = (32 / 8) + (32 / 8);
|
|
|
|
function decode_payload(payload_base64, key_hex) {
|
|
let payload_buffer_enc = Buffer.from(payload_base64, "base64");
|
|
let key_buffer = Buffer.from(key_hex, "hex");
|
|
|
|
// console.log(payload_buffer_enc);
|
|
|
|
let aes_ecb = new aes.ModeOfOperation.ecb(key_buffer);
|
|
let payload_buffer = Buffer.from(aes_ecb.decrypt(payload_buffer_enc).buffer);
|
|
|
|
// console.debug(payload_buffer);
|
|
// console.debug(`Offsets: ${offset_id}, ${offset_lat}, ${offset_lng}`);
|
|
// console.debug(`Message hex: ${payload_buffer.toString("hex")}`)
|
|
|
|
return {
|
|
id: payload_buffer.readUInt32LE(offset_id),
|
|
latitude: payload_buffer.readFloatLE(offset_lat),
|
|
longitude: payload_buffer.readFloatLE(offset_lng)
|
|
};
|
|
}
|
|
|
|
export { decode_payload };
|