function decryptPayload
decryptPayload(
message: BaichuanMessage,
aesKey: Uint8Array
): Uint8Array

Decrypts the binary payload of a received message, such as a snapshot chunk.

When the body names an <encryptLen>, that many leading payload bytes are AES-encrypted and the rest is plain. Without one the payload is plain.

Examples

Read a plain payload

import { assertEquals } from "@std/assert";
import { decryptPayload } from "@hertzg/reolink-api/protocol/message";

const payload = decryptPayload({
  header: {
    cmdId: 109,
    bodyLength: 3,
    channelId: 1,
    messageId: 7,
    status: 200,
    messageClass: 0x1464,
    payloadOffset: 0,
  },
  body: new Uint8Array(0),
  payload: Uint8Array.of(0xff, 0xd8, 0xff),
}, new TextEncoder().encode("08822D7143979103"));

assertEquals(payload, Uint8Array.of(0xff, 0xd8, 0xff));

Parameters

The received message.

aesKey: Uint8Array

The session key from login.

Return Type

The plain payload.

Usage

import { decryptPayload } from "protocol/message.ts";