{"id":16081,"library":"http_ece","title":"HTTP Encrypted Content-Encoding","description":"This package provides a simple, direct implementation of the HTTP Encrypted Content-Encoding (RFC 8188) specification for Node.js environments. It enables the encryption and decryption of HTTP request and response bodies, primarily used in Web Push applications. The current stable version is 1.2.1. While not on a fixed release schedule, updates occur as needed, with the latest focusing on development tooling. Its primary differentiator is its focused adherence to RFC 8188, offering functions for both symmetric and static-ephemeral ECDH encryption modes, without additional layers or external runtime dependencies beyond Node.js built-ins, making it a lightweight option for content encryption. It targets modern Node.js environments, requiring Node.js version 16 or newer.","status":"active","version":"1.2.1","language":"javascript","source_language":"en","source_url":"https://github.com/martinthomson/encrypted-content-encoding","tags":["javascript"],"install":[{"cmd":"npm install http_ece","lang":"bash","label":"npm"},{"cmd":"yarn add http_ece","lang":"bash","label":"yarn"},{"cmd":"pnpm add http_ece","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This is the standard CommonJS import pattern. The package is primarily distributed as a CommonJS module.","symbol":"ece (CommonJS)","correct":"const ece = require('http_ece');"},{"note":"When using ES Modules, the CommonJS `module.exports` object is imported as the default export. Attempting to destructure `ece` will result in `undefined` for named imports.","wrong":"import { ece } from 'http_ece';","symbol":"ece (ES Modules)","correct":"import ece from 'http_ece';"},{"note":"The `encrypt` and `decrypt` functions are methods of the `ece` module object, not named exports from the package root.","wrong":"import { encrypt, decrypt } from 'http_ece';","symbol":"encrypt / decrypt methods","correct":"import ece from 'http_ece'; ece.encrypt(data, params);"}],"quickstart":{"code":"import ece from 'http_ece';\nimport { randomBytes } from 'crypto';\nimport assert from 'assert';\n\nasync function runEncryptionExample() {\n  // Data to be encrypted – a Buffer is expected.\n  const data = Buffer.from('This is some sensitive data that needs to be encrypted before sending over HTTP. It should be long enough to test the encryption process properly and verify integrity.');\n\n  // Generate random keys and salts for encryption parameters. These must be kept secret and shared out-of-band.\n  const parameters = {\n    key: randomBytes(16).toString('base64url'), // 16 bytes for a 128-bit key\n    salt: randomBytes(16).toString('base64url') // 16 bytes for a 128-bit salt\n  };\n\n  console.log('Original Data:', data.toString('utf8'));\n  console.log('Encryption Parameters (base64url):', parameters);\n\n  // Encrypt the data using the generated parameters\n  const encrypted = ece.encrypt(data, parameters);\n  console.log('Encrypted Data (Buffer):', encrypted);\n\n  // Decrypt the data using the same parameters\n  const decrypted = ece.decrypt(encrypted, parameters);\n  console.log('Decrypted Data (Buffer):', decrypted);\n\n  // Verify that the decrypted data matches the original data\n  assert.equal(decrypted.compare(data), 0, 'Decrypted data does not match original!');\n  console.log('Verification successful: Decrypted data matches original.');\n}\n\nrunEncryptionExample().catch(console.error);\n","lang":"javascript","description":"This quickstart demonstrates how to encrypt and decrypt a Buffer using the `http_ece` module with randomly generated keys and salts, and then verifies the integrity of the decrypted data."},"warnings":[{"fix":"Ensure your project's Node.js environment is version 16 or newer. Update Node.js using `nvm install 16` (or higher) and `nvm use 16` or similar version management tools.","message":"The `http_ece` package explicitly requires Node.js version 16 or higher. Running it on older Node.js versions may lead to unexpected errors due to unavailable APIs or module loading issues.","severity":"gotcha","affected_versions":"<16.0.0"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"Replace `const ece = require('http_ece');` with `import ece from 'http_ece';` for ES module compatibility.","cause":"Attempting to use `require()` in a JavaScript file that is treated as an ES module (e.g., a `.mjs` file or a file in a package with `\"type\": \"module\"`).","error":"TypeError: require is not defined in ES module scope"},{"fix":"Ensure you are using the correct default import for ES modules: `import ece from 'http_ece';`. The CommonJS `module.exports` object is the default export.","cause":"This usually occurs when trying to call `ece.encrypt` after an incorrect ES module import, such as `import { ece } from 'http_ece';`, which would make `ece` undefined or an empty object.","error":"TypeError: Cannot read properties of undefined (reading 'encrypt')"}],"ecosystem":"npm"}