🚀 Launch Week Day 5:Introducing Immutable Scans.Learn More →
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.

latest
Source
npmnpm
Version
1.0.3
Version published
Maintainers
2
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