UNPKG

iobroker.gree-hvac

Version:
85 lines (84 loc) 3.42 kB
"use strict"; var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var encryptor_exports = {}; __export(encryptor_exports, { decryptV1: () => decryptV1, decryptV2: () => decryptV2, defaultKey: () => defaultKey, defaultKeyGCM: () => defaultKeyGCM, encryptV1: () => encryptV1, encryptV2: () => encryptV2 }); module.exports = __toCommonJS(encryptor_exports); var crypto = __toESM(require("node:crypto")); const defaultKey = Buffer.from("a3K8Bx%2r8Y7#xDh", "utf8"); const defaultKeyGCM = Buffer.from("{yxAHAY_Lm6pbC/<", "utf8"); const ECB_ALG = "aes-128-ecb"; const GCM_ALG = "aes-128-gcm"; const GCM_NONCE = Buffer.from("5440784449675a516c5e6313", "hex"); const GCM_AEAD = Buffer.from("qualcomm-test"); function encryptV2(data, key = defaultKeyGCM) { const cipher = crypto.createCipheriv(GCM_ALG, key, GCM_NONCE); cipher.setAAD(GCM_AEAD); const str = cipher.update(JSON.stringify(data), "utf8", "base64"); const encPack = str + cipher.final("base64"); const rawTag = cipher.getAuthTag(); const encTag = rawTag.toString("base64").toString(); return { encPack, encTag }; } function decryptV2(data, key = defaultKeyGCM, tag) { const decipher = crypto.createDecipheriv(GCM_ALG, key, GCM_NONCE); decipher.setAAD(GCM_AEAD); if (tag) { const decTag = Buffer.from(tag, "base64"); decipher.setAuthTag(decTag); } const str = decipher.update(data, "base64", "utf8"); return JSON.parse(str + decipher.final("utf8")); } function encryptV1(data, key = defaultKey) { const cipher = crypto.createCipheriv(ECB_ALG, key, ""); const str = cipher.update(JSON.stringify(data), "utf8", "base64"); return str + cipher.final("base64"); } function decryptV1(data, key = defaultKey) { const decipher = crypto.createDecipheriv(ECB_ALG, key, ""); const str = decipher.update(data, "base64", "utf8"); return JSON.parse(str + decipher.final("utf8")); } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { decryptV1, decryptV2, defaultKey, defaultKeyGCM, encryptV1, encryptV2 }); //# sourceMappingURL=encryptor.js.map