{"_id":"@abubu/kaos","_rev":"2-410e8aafcf546ad0d7a9be7c0d603b55","name":"@abubu/kaos","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@abubu/kaos","version":"1.0.0","description":"A simple stream encrypter","main":"index.js","scripts":{"test":"echo \"Error: no test specified\" && exit 1","lint":"standard --fix","mocha":"mocha","mocha-dbg":"node --inspect-brk node_modules/mocha/bin/_mocha"},"repository":{"type":"git","url":"git+https://github.com/ArnaudBuchholz/kaos.git"},"keywords":["stream","encryption"],"author":{"name":"Arnaud Buchholz"},"license":"MIT","bugs":{"url":"https://github.com/ArnaudBuchholz/kaos/issues"},"homepage":"https://github.com/ArnaudBuchholz/kaos#readme","devDependencies":{"colors":"^1.4.0","lodash":"^4.17.19","mocha":"^8.0.1","standard":"^14.3.4"},"mocha":{"diff":false,"spec":["tests/mocha/*.test.js"]},"standard":{"globals":["process","describe","it","before","after"]},"gitHead":"c476a5c531faee9df9cb124a0af1914d8ae1fb7a","_id":"@abubu/kaos@1.0.0","_nodeVersion":"12.16.3","_npmVersion":"6.14.7","dist":{"integrity":"sha512-1vQ8a5I8+ZO5Yn/OiEsNDfrBu02z5q9rupc+WlS0RL1ow+RTWi9BjF9nA9gGew2O5MxHvI0zYqUt+cnsLx2Bhg==","shasum":"f29baaacea03d034c64477ba62c807f4ca7cf3da","tarball":"https://registry.npmjs.org/@abubu/kaos/-/kaos-1.0.0.tgz","fileCount":9,"unpackedSize":13681,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfHlQUCRA9TVsSAnZWagAAbRUP/iHxwV1Z3uIngZxA/AZk\nf2ZmHtuiZK/v01CZkmU6OI63dIkFzdG+R8fiO07cIv7MTPAsDLaMPaEnd6jU\nMADxMZ/1KTGYLGkav5J5QvpcKz4kSv7jBWJ67zf/h8QcOAHGVHvrXm5hG1yy\n5nihByOYsrFmCUquXH4Ve0Elz4Zyx3ajj0daL6XPPn7cXs6uNtC7EUsnFxwb\neVSXH23b3tjI/K8paWSayw/Xi7nyBbb7YXl2fxR47t43QCyZqENjW1rV52Rj\nLq9bXeyu6jysw0qkT9XY2m5JIvkYSFqqBvrXqYAASSQvw8S0+dqYTXFyDQ61\nJmJkJczHimK37fxNTIwHb65ez5CADTS4GHVgroC93XIKIzxR4n9xSTw3djWz\nK5diWlQRrxDAKLKi81ot5P1JMvncglPib9d1pu2v2sox2eSDU7LBosAC82QI\nA0zRFQ67YM0T3COjJo76B7+7hk7w3D2OXcVr805klxZoXUxAduRIvCJEaekf\nq8idbNhlyqa9Kh+FAIRqGJ7m3Dzpep62rPHqFx2GNMFY36pjUVGgekoIMw/Q\nrvBVeBAKZlb9gU+3ZLVUMJYRGFeC6Hr+OMGFFSpZcTzO7L1M+HOPuCk3yFZd\nAh/NI3ZQJH/EtD94qn/NgFqfX8IgVc1kjfypPPqeUgA5Oh5wUV/XtJRqySO8\noby9\r\n=VF6k\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIAaEAfrEMKFNSowc0NqJUISpcrdxdi9P5rp1YDHp9kZUAiEAt9RzKg3ga/XRYEpJgAdKc2p6fdONpsuVSPq3TUikdlE="}]},"maintainers":[{"name":"arnaud.buchholz","email":"arnaud.buchholz@free.fr"}],"_npmUser":{"name":"arnaud.buchholz","email":"arnaud.buchholz@free.fr"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/kaos_1.0.0_1595823124079_0.12577478921195806"},"_hasShrinkwrap":false,"deprecated":"Please use https://www.npmjs.com/package/kaos instead"}},"time":{"created":"2020-07-27T04:12:03.843Z","1.0.0":"2020-07-27T04:12:04.238Z","modified":"2022-04-04T11:03:58.342Z"},"maintainers":[{"name":"arnaud.buchholz","email":"arnaud.buchholz@free.fr"}],"description":"A simple stream encrypter","homepage":"https://github.com/ArnaudBuchholz/kaos#readme","keywords":["stream","encryption"],"repository":{"type":"git","url":"git+https://github.com/ArnaudBuchholz/kaos.git"},"author":{"name":"Arnaud Buchholz"},"bugs":{"url":"https://github.com/ArnaudBuchholz/kaos/issues"},"license":"MIT","readme":"# &#975;&#592;&oplus;&sopf;\n\nKaos is a simple but efficient *(and hopefully hard to break)* data encrypter.\n\n* It is tiny with **no** dependencies\n* It implements [Node.js' **Transform** streams](https://nodejs.org/api/stream.html#stream_class_stream_transform)\n* It enables encryption / decryption by **chunks**\n* Two consecutive encryptions with the **same unsalted key** generates **different outputs**\n\n## API\n\n### `Stream.Transform encrypt (key, offset = undefined)`\n\nThe `encrypt` API accepts two parameters and returns a [Stream.Transform](https://nodejs.org/api/stream.html#stream_class_stream_transform) instance.\n\nThe first parameter is the **encryption key**, it can be :\n* A string\n* A [Buffer](https://nodejs.org/api/buffer.html#buffer_class_buffer) instance\n* A [Stream.Readable](https://nodejs.org/api/stream.html#stream_class_stream_readable) instance\n* A key instance *(used for chunks, see below)*\n\nIf an unsupported type is used an [Error](https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Objets_globaux/Error) with the message `Unsupported key type` is thrown.\n\nThe second parameter must be used **only** when the encryption is done by **chunks** *(see example)*.\n\n```javascript\n// Simple encryption\n\nconst { promisify } = require('util')\nconst pipeline = promisify(require('stream').pipeline)\nconst { createReadStream, createWriteStream } = require('fs')\nconst { encrypt } = require('@abubu/kaos')\n\npipeline(\n  createReadStream('file to encrypt'),\n  encrypt('my secret key'),\n  createWriteStream('encrypted file')\n)\n  .then(() => console.log('Encryption succeeded.'))\n  .catch(() => console.log('Encryption failed.'))\n```\n\n### Encryption by chunks\n\nIf the data to encrypt is **available by chunks** *(for instance : uploaded by packets)*, the **same salted key** must be used for all parts. The start offset of each chunk must be specified for all **but** the first one.\n\n```javascript\n// Chunks encryption\n\nconst { promisify } = require('util')\nconst pipeline = promisify(require('stream').pipeline)\nconst { createReadStream, createWriteStream } = require('fs')\nconst { key, encrypt } = require('@abubu/kaos')\n\nconst myKey = key('my secret key')\n\nmyKey.salt()\n  // mySaltedKey must be reused for each chunks\n  .then(mySaltedKey => pipeline(\n    createReadStream('file to encrypt', { start: 0, end: 50 }),\n    encrypt(mySaltedKey), // /!\\ No offset fo the first chunk\n    createWriteStream('encrypted file')\n  ))\n  .then(() => pipeline(\n    createReadStream('file to encrypt', { start: 51 }),\n    encrypt(mySaltedKey, 51), // Start offset of this chunk\n    createWriteStream('encrypted file', { flags: 'r+', start: 51 })\n  ))\n  .then(() => console.log('Encryption succeeded.'))\n  .catch(() => console.log('Encryption failed.'))\n```\n\n### `Stream.Transform decrypt (key, range = undefined)`\n\nThe `decrypt` API accepts two parameters and returns a [Stream.Transform](https://nodejs.org/api/stream.html#stream_class_stream_transform) instance.\n\nThe first parameter is the encryption key, similar to the `encrypt` API.\n\nThe second parameter must be used only when the decryption is done by chunks *(see example)*.\n\n**NOTE :** the decryption algorithm **does not verify** if the data is correctly decrypted.\n\n```javascript\n// Simple decryption\n\nconst { promisify } = require('util')\nconst pipeline = promisify(require('stream').pipeline)\nconst { createReadStream, createWriteStream } = require('fs')\nconst { decrypt } = require('@abubu/kaos')\n\npipeline(\n  createReadStream('file to decrypt'),\n  decrypt('my secret key'),\n  createWriteStream('decrypted file')\n)\n  .then(() => console.log('Decryption succeeded.'))\n  .catch(() => console.log('Decryption failed.'))\n```\n\n### Decryption by chunks\n\nWhen only a **specific part** of the message must be decoded, the `key` API provides information about the **ranges to load** from the encrypted data.\n\nThe first step consists in reading the **key salt**. Once salted, the key can be **reused** to decode other ranges of the **same encrypted data**.\n\n```javascript\n// Chunks decryption\n\nconst { promisify } = require('util')\nconst pipeline = promisify(require('stream').pipeline)\nconst { createReadStream, createWriteStream } = require('fs')\nconst { key, decrypt } = require('@abubu/kaos')\n\nconst myKey = key('my secret key')\n\nmyKey.saltRange()\n  .then(range => myKey.salt(createReadStream('file to decrypt', range)))\n  // To decode bytes between 1000 and 1100 (inclusively)\n  .then(saltedKey => saltedKey.byteRange(1000, 1100))\n  .then(range => pipeline(\n    createReadStream('file to decrypt', range),\n    decrypt(saltedKey, range),\n    createWriteStream('decrypted byte range')\n  ))\n  .then(() => console.log('Decryption succeeded.'))\n  .catch(() => console.log('Decryption failed.'))\n```\n","readmeFilename":"README.md"}