decryptBody(message: BaichuanMessage,aesKey?: Uint8Array): string
Decrypts a received body into XML text.
A 20-byte header names the cipher in the low byte of encryption: 0x01
or 0x12 XOR, 0x02 or 0x03 AES, 0x00 none. A 24-byte header names
none, so AES (when a key is given), XOR and plain text are tried in that
order. The first result that starts with <?xml wins, which is how
reolink_aio decides too.
Decrypt an XOR-encrypted nonce reply
Decrypt an XOR-encrypted nonce reply
import { assertEquals } from "@std/assert"; import { xorCipher } from "@hertzg/reolink-api/encoding/cipher"; import { decryptBody } from "@hertzg/reolink-api/protocol/message"; const xml = "<?xml version=\"1.0\" ?><body><nonce>abc</nonce></body>"; const body = xorCipher(new TextEncoder().encode(xml), 250); const text = decryptBody({ header: { cmdId: 1, bodyLength: body.length, channelId: 250, messageId: 1, encryption: 0xdd01, messageClass: 0x1466, }, body, payload: new Uint8Array(0), }); assertEquals(text, xml);
message: BaichuanMessage
The received message.
optional
aesKey: Uint8Array
The session key from login, if logged in.