UNPKG

@azure/cosmos

Version:
55 lines (54 loc) 2.4 kB
var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; 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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var DataEncryptionKey_exports = {}; __export(DataEncryptionKey_exports, { DataEncryptionKey: () => DataEncryptionKey }); module.exports = __toCommonJS(DataEncryptionKey_exports); var import_node_crypto = require("node:crypto"); class DataEncryptionKey { rootKeyBuffer; keySizeInBits = 256; keySizeInBytes = this.keySizeInBits / 8; encryptionKeyBuffer; macKeyBuffer; ivKeyBuffer; name; constructor(rootKey, name) { if (rootKey.length !== this.keySizeInBytes) { throw new Error("Invalid root key size"); } this.rootKeyBuffer = rootKey; this.name = name; const encryptionKeySalt = `Microsoft SQL Server cell encryption key with encryption algorithm:AEAD_AES_256_CBC_HMAC_SHA256 and key length:${this.keySizeInBits}`; const macKeySalt = `Microsoft SQL Server cell MAC key with encryption algorithm:AEAD_AES_256_CBC_HMAC_SHA256 and key length:${this.keySizeInBits}`; const ivKeySalt = `Microsoft SQL Server cell IV key with encryption algorithm:AEAD_AES_256_CBC_HMAC_SHA256 and key length:${this.keySizeInBits}`; this.encryptionKeyBuffer = this.getHmacWithSha256(encryptionKeySalt, this.rootKeyBuffer); this.macKeyBuffer = this.getHmacWithSha256(macKeySalt, this.rootKeyBuffer); this.ivKeyBuffer = this.getHmacWithSha256(ivKeySalt, this.rootKeyBuffer); } getHmacWithSha256(plainText, key) { const hmac = (0, import_node_crypto.createHmac)("sha256", key); hmac.update(Buffer.from(plainText, "utf16le")); return hmac.digest(); } } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { DataEncryptionKey });