UNPKG

node-ciphers

Version:

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

41 lines (39 loc) 1.25 kB
import { BaseDesCipher } from "./_internals/base/index.js"; //#region src/des/ecb.ts var Ecb = class extends BaseDesCipher { constructor(key, encodingOptions) { super(key, "ecb", encodingOptions); } decrypt(encryptedData, iv, encodingOptions, decipherOptions) { try { return this.createOkResult(this.getDecipherResult(this.createDecipher(null, decipherOptions), encryptedData, encodingOptions)); } catch (error) { return this.createErrorResult(error); } } decryptToJson(encryptedData, iv, encodingOptions, decipherOptions) { const result = this.decrypt(encryptedData, iv, encodingOptions, decipherOptions); if (!result.ok) return result; return this.parseJson(result.value); } encrypt(data, encodingOptions, cipherOptions) { try { return this.createOkResult({ data: this.getCipherResult(this.createCipher(null, cipherOptions), data, encodingOptions), iv: null }); } catch (error) { return this.createErrorResult(error); } } encryptJson(data, encodingOptions, cipherOptions) { try { return this.encrypt(JSON.stringify(data), encodingOptions, cipherOptions); } catch (error) { return this.createErrorResult(error); } } }; //#endregion export { Ecb }; //# sourceMappingURL=ecb.js.map