Latest Socket ResearchMalicious Chrome Extension Performs Hidden Affiliate Hijacking.Details
Socket
Book a DemoInstallSign in
Socket

encryption-encoding

Package Overview
Dependencies
Maintainers
2
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

encryption-encoding

Compact encoding for versioned encrypted values with automatic string/buffer handling.

Source
npmnpm
Version
1.0.2
Version published
Weekly downloads
2K
76.01%
Maintainers
2
Weekly downloads
 
Created
Source

encryption-encoding

Versioned encryption encoding using hyperschema.

Installation

npm install encryption-encoding

Usage

const sodium = require('sodium-universal')
const b4a = require('b4a')
const { encrypt, decrypt } = require('encryption-encoding')

const password = b4a.alloc(32)
// ... fill password

const encrypted = await encrypt(plaintext, async (value) => {
  const buffer = b4a.allocUnsafe(
    value.byteLength +
    sodium.crypto_secretbox_MACBYTES +
    sodium.crypto_secretbox_NONCEBYTES
  )
  const nonce = buffer.subarray(0, sodium.crypto_secretbox_NONCEBYTES)
  const box = buffer.subarray(nonce.byteLength)

  sodium.randombytes_buf(nonce)
  sodium.crypto_secretbox_easy(box, value, nonce, password)

  return { value: buffer, version: 1 }
})

const decrypted = await decrypt(encrypted, async ({ value, version }) => {
  const nonce = value.subarray(0, sodium.crypto_secretbox_NONCEBYTES)
  const box = value.subarray(nonce.byteLength)
  const output = b4a.allocUnsafe(box.byteLength - sodium.crypto_secretbox_MACBYTES)

  sodium.crypto_secretbox_open_easy(output, box, nonce, password)
  return output
})

API

await encrypt(data, callback)

Calls callback(data) which should return { value, version }, then encodes the result using hyperschema.

await decrypt(buffer, callback)

Decodes the buffer to { version, value }, passes it to callback, and returns the result.

License

Apache-2.0

Keywords

pear

FAQs

Package last updated on 15 Jan 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts