# secret-blob

> Tiny module for easy encryption of Buffers

Latest version **1.1.0** (published 2020-06-16) · ISC license · 0 weekly downloads

## Install

```sh
npm install secret-blob
pnpm add secret-blob
yarn add secret-blob
bun add secret-blob
```

Provides the commands `secret-blob-keygen`, `secret-blob-decrypt`, `secret-blob-encrypt`.

## Health

**Score 23/100 (F)** — status: abandoned.

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2020-06-16 |
| First published | 2020-06-16 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | separate (@types/secret-blob) |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 8.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 32 |
| Author | Emil Bay |
| Maintainers | emilbayes |

## Links

- npm: https://www.npmjs.com/package/secret-blob
- Repository: https://github.com/emilbayes/secret-blob
- Homepage: https://github.com/emilbayes/secret-blob#readme
- Issues: https://github.com/emilbayes/secret-blob/issues
- npm.io page: https://npm.io/package/secret-blob

## Dependencies (2)

- [nanoassert](https://npm.io/package/nanoassert.md) ^2.0.0
- [sodium-native](https://npm.io/package/sodium-native.md) ^3.1.1

## Recent versions

- 1.1.0 (latest) — 2020-06-16
- 1.0.1 — 2020-06-16
- 1.0.0 — 2020-06-16

## README

# `secret-blob`

[![Build Status](https://travis-ci.org/emilbayes/secret-blob.svg?branch=master)](https://travis-ci.org/emilbayes/secret-blob)

> Tiny module for easy encryption of Buffers

## Usage

```js
const secretBlob = require('secret-blob')

const key = secretBlob.keygen()

const message = Buffer.from('Hello world')

const encrypted = secretBlob.encrypt(message, key)

const decrypted = secretBlob.decrypt(encrypted, key)

console.log(decrypted.toString()) // Hello world
```

## API

### `const key = secretBlob.keygen([key])`

Generate a new key. Optionally pass `Buffer` `key` to write to.
Must be `secretBlob.KEYBYTES` long.

Returns a `sodium-native` secret `Buffer`.

### `const ciphertext = secretBlob.encrypt(plaintext, key, [ciphertext])`

Encrypt `plaintext` under `key`.  Optionally pass `Buffer` `ciphertext` to write
to. Must be `secretBlob.encryptLength(plaintext)` long.

Returns a normal `Buffer`.

### `const byteLength = secretBlob.encryptLength(plaintext)`

Returns the number of bytes required to encrypt `plaintext`.
Simply `plaintext.byteLength + secretBlob.HEADERBYTES`.

### `const plaintext = secretBlob.decrypt(ciphertext, key, [plaintext])`

Decrypt `ciphertext` under `key`.  Optionally pass `Buffer` `plaintext` to write
to. Must be `secretBlob.decryptLength(plaintext)` long.

Returns a `sodium-native` secret `Buffer`.

### `const byteLength = secretBlob.decryptLength(ciphertext)`

Returns the number of bytes required to encrypt `ciphertext`.
Simply `ciphertext.byteLength - secretBlob.HEADERBYTES`.

### Constants

- `KEYBYTES`: Byte length of a key
- `HEADERBYTES`: Byte length of the header added to ciphertext

## Install

```sh
npm install secret-blob
```

## License

[ISC](LICENSE)

---
_Source: https://npm.io/package/secret-blob · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
