2019-07-04 16:18:38 +00:00
|
|
|
"use strict";
|
|
|
|
|
2019-07-15 12:49:44 +00:00
|
|
|
import aes from 'aes-js';
|
|
|
|
|
2019-07-04 16:18:38 +00:00
|
|
|
const offset_id = 0;
|
|
|
|
const offset_lat = 32 / 8;
|
|
|
|
const offset_lng = (32 / 8) + (32 / 8);
|
|
|
|
|
2019-07-15 12:49:44 +00:00
|
|
|
function decode_payload(payload_base64, key_hex) {
|
|
|
|
let payload_buffer_enc = Buffer.from(payload_base64, "base64");
|
|
|
|
let key_buffer = Buffer.from(key_hex, "hex");
|
|
|
|
|
2019-07-15 13:31:39 +00:00
|
|
|
console.log(payload_buffer_enc);
|
|
|
|
|
2019-07-15 12:49:44 +00:00
|
|
|
let aes_ecb = new aes.ModeOfOperation.ecb(key_buffer);
|
2019-07-15 13:31:39 +00:00
|
|
|
let payload_buffer = Buffer.from(aes_ecb.decrypt(payload_buffer_enc).buffer);
|
2019-07-04 16:18:38 +00:00
|
|
|
|
2019-07-15 13:31:39 +00:00
|
|
|
console.debug(payload_buffer);
|
2019-07-09 12:14:12 +00:00
|
|
|
// console.debug(`Offsets: ${offset_id}, ${offset_lat}, ${offset_lng}`);
|
|
|
|
// console.debug(`Message hex: ${payload_buffer.toString("hex")}`)
|
|
|
|
|
2019-07-04 16:18:38 +00:00
|
|
|
return {
|
|
|
|
id: payload_buffer.readUInt32LE(offset_id),
|
2019-07-09 12:14:12 +00:00
|
|
|
latitude: payload_buffer.readFloatLE(offset_lat),
|
|
|
|
longitude: payload_buffer.readFloatLE(offset_lng)
|
2019-07-04 16:18:38 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export { decode_payload };
|