UNPKG

node-ciphers

Version:

Lightweight AES and DES encryption library for Node.js, featuring flexible encoding, multiple cipher modes, and TypeScript support.

35 lines (33 loc) 1.12 kB
import { availableCiphers } from "../../../_internals/constants.js"; import { BaseCipher } from "../../../_internals/base-cipher.js"; import { createCipheriv, createDecipheriv } from "node:crypto"; //#region src/des/_internals/base/index.ts const keyLengthToModePrefixMap = { 8: "", 16: "-ede", 24: "-ede3" }; var BaseDesCipher = class extends BaseCipher { #algorithm; #key; constructor(key, mode, encodingOptions) { super(encodingOptions); this.#key = this.dataToBuffer(key, this.encodingOptions.key); const desModePrefix = keyLengthToModePrefixMap[this.#key.byteLength]; if (desModePrefix === void 0) throw new Error("Invalid key length"); this.#algorithm = `des${desModePrefix}-${mode}`; if (!availableCiphers.includes(this.#algorithm)) throw new Error("Invalid algorithm"); } get algorithm() { return this.#algorithm; } createCipher(iv, options) { return createCipheriv(this.#algorithm, this.#key, iv, options); } createDecipher(iv, options) { return createDecipheriv(this.#algorithm, this.#key, iv, options); } }; //#endregion export { BaseDesCipher }; //# sourceMappingURL=index.js.map