# @47ng/cloak

> Serialized AES-GCM 256 encryption, decryption and key management in the browser & Node.js

Latest version **1.2.0** (published 2024-09-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install @47ng/cloak
pnpm add @47ng/cloak
yarn add @47ng/cloak
bun add @47ng/cloak
```

Provides the command `cloak`.

## Health

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

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

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.0 |
| Published | 2024-09-24 |
| First published | 2019-12-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 8 |
| Unpacked size | 37.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 63 |
| Author | François Best |
| Maintainers | franky47 |
| Keywords | cryptography, aes-256-gcm |

## Links

- npm: https://www.npmjs.com/package/@47ng/cloak
- Repository: https://github.com/47ng/cloak
- Homepage: https://github.com/47ng/cloak#readme
- Issues: https://github.com/47ng/cloak/issues
- npm.io page: https://npm.io/package/@47ng/cloak

## Dependencies (8)

- [chalk](https://npm.io/package/chalk.md) ^4.1.2
- [s-ago](https://npm.io/package/s-ago.md) ^2.2.0
- [dotenv](https://npm.io/package/dotenv.md) ^10.0.0
- [commander](https://npm.io/package/commander.md) ^8.3.0
- [@47ng/codec](https://npm.io/package/@47ng/codec.md) ^1.0.1
- [@stablelib/hex](https://npm.io/package/@stablelib/hex.md) ^1.0.1
- [@stablelib/utf8](https://npm.io/package/@stablelib/utf8.md) ^1.0.1
- [@stablelib/base64](https://npm.io/package/@stablelib/base64.md) ^1.0.1

## Alternatives

- [@gemini-wallet/core](https://npm.io/package/@gemini-wallet/core.md) — 515.6K weekly downloads
- [utility](https://npm.io/package/utility.md) — 416.6K weekly downloads
- [@primno/dpapi](https://npm.io/package/@primno/dpapi.md) — 7.2K weekly downloads
- [pi-readseek](https://npm.io/package/pi-readseek.md) — 3.7K weekly downloads
- [@emilia-protocol/verify](https://npm.io/package/@emilia-protocol/verify.md) — 1.1K weekly downloads

## Recent versions

- 1.2.0 (latest) — 2024-09-24
- 1.2.0-beta.1 (beta) — 2024-09-24
- 1.1.0 — 2021-12-13
- 1.1.0-beta.2 — 2021-11-25
- 1.1.0-beta.1 — 2021-11-25
- 1.0.1 — 2020-12-22
- 1.0.0 — 2020-05-15
- 0.15.1 — 2020-01-18
- 0.15.0 — 2020-01-14
- 0.14.1 — 2020-01-13
- 0.14.0 — 2020-01-12
- 0.13.0 — 2020-01-12
- 0.12.0 — 2020-01-12
- 0.11.0 — 2020-01-12
- 0.10.0 — 2020-01-09
- … 10 more at https://npm.io/package/@47ng/cloak/versions

## README

<h1 align="center"><code>@47ng/cloak</code></h1>

<div align="center">

[![NPM](https://img.shields.io/npm/v/@47ng/cloak?color=red)](https://www.npmjs.com/package/@47ng/cloak)
[![MIT License](https://img.shields.io/github/license/47ng/cloak.svg?color=blue)](https://github.com/47ng/cloak/blob/next/LICENSE)
[![Continuous Integration](https://github.com/47ng/cloak/workflows/Continuous%20Integration/badge.svg?branch=next)](https://github.com/47ng/cloak/actions)
[![Coverage Status](https://coveralls.io/repos/github/47ng/cloak/badge.svg?branch=next)](https://coveralls.io/github/47ng/cloak?branch=next)

</div>

<p align="center">
  Serialized AES-GCM 256 encryption, decryption and key management in the browser & Node.js.
</p>

## Installation

```shell
$ yarn add @47ng/cloak
# or
$ npm i @47ng/cloak
```

## CLI

The package comes with a CLI tool you can use to generate and manage keys, as
well as encrypting and decrypting data in the terminal:

```shell
$ cloak --help
Usage: cloak [options] [command]

Options:
  -h, --help                 output usage information

Commands:
  generate                   Generate an AES-GCM key
  encrypt [options] [key]    Encrypt stdin
  decrypt                    Decrypt stdin
  revoke <keyFingerprint>    Remove a key from the environment keychain
  keychain [options] [full]  List the contents of the environment keychain

# Start by generating an empty keychain and master key:
$ cloak generate
Key:          k1.aesgcm256.DL2G9PQeZ9r65J59pph6dy9Sk4fBLEZ3CTQZsandgYE=
Fingerprint:  6f28c026

Generated new empty keychain:
export CLOAK_MASTER_KEY=k1.aesgcm256.DL2G9PQeZ9r65J59pph6dy9Sk4fBLEZ3CTQZsandgYE=
export CLOAK_KEYCHAIN=v1.aesgcm256.6f28c026.yhCUkzv5gOyHJ2M_.jrGSf2_MPVofk-kSDgnYzvEy

# Copy/paste the exports into your terminal
# (the CLI does not mutate your environment directly)
$ export CLOAK_MASTER_KEY=k1.aesgcm256.DL2G9PQeZ9r65J59pph6dy9Sk4fBLEZ3CTQZsandgYE=
$ export CLOAK_KEYCHAIN=v1.aesgcm256.6f28c026.yhCUkzv5gOyHJ2M_.jrGSf2_MPVofk-kSDgnYzvEy

# Generate a key to use for encryption
$ cloak generate
Key:          k1.aesgcm256.pHLFYdaqXut62LoFbt8KV80x_YNyZPmY0kQaPhJ0Ehc=
Fingerprint:  cd38bcc4

Updated keychain:
export CLOAK_MASTER_KEY=k1.aesgcm256.DL2G9PQeZ9r65J59pph6dy9Sk4fBLEZ3CTQZsandgYE=
export CLOAK_KEYCHAIN=v1.aesgcm256.6f28c026.jr9fqMA_RfNhIjHz.lo4IfIYfZ0zxrdSns_ibWq6YX1D5AnzN-fhUF0CKVx5dRVIo0x-Atumr9WZqpHOeEIWT5bEGFKHhxGkFdwk2vg5TZQNk5Rj_jo3hnfSLaFAYncG59dB  jUkz1JE0Plq2d-GR1AbDs6P18VzOG_JrU

To use this new key as default for encryption:
export CLOAK_CURRENT_KEY=cd38bcc4

# Encrypt sdtin
$ echo 'Hello, World !' | cloak encrypt
v1.aesgcm256.cd38bcc4.yxAp2iONy7zYOhbs.X2zmGpmGw9a7tiSnyukEW8Ac-2IIcIENW5uHxtHYyA==

# Decrypt stdin
$ echo 'v1.aesgcm256.cd38bcc4.yxAp2iONy7zYOhbs.X2zmGpmGw9a7tiSnyukEW8Ac-2IIcIENW5uHxtHYyA==' | cloak decrypt
Hello, World !
```

## Programmatic Usage

```ts
// Works in the browser or in Node.js

import { generateKey, encryptString, decryptString } from '@47ng/cloak'

const demo = async () => {
  const key = generateKey()
  const cipher = await encryptString('Hello, World', key)
  const decipher = await decryptString(cipher, key)
}
```

## License

[MIT](./LICENSE) - Made with ❤️ by [François Best](https://francoisbest.com)

Using this package at work ? [Sponsor me](https://github.com/sponsors/franky47) to help with support and maintenance.

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