UNPKG

node-ciphers

Version:

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

48 lines (44 loc) 1.49 kB
'use strict'; const index = require('./base/index.cjs'); class Ecb extends index.BaseAesCipher { constructor(key, encodingOptions) { super(key, 'ecb', encodingOptions); } decrypt(encryptedData, // @ts-expect-error Allow iv to be null. 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); } } } exports.Ecb = Ecb; //# sourceMappingURL=ecb.cjs.map