# cosmic-crypt

> utility to reduce boilerplate when encrypting/decrypting text

Latest version **2.0.0** (published 2026-06-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install cosmic-crypt
pnpm add cosmic-crypt
yarn add cosmic-crypt
bun add cosmic-crypt
```

Provides the command `cosmic-crypt`.

## Health

**Score 60/100 (C)** — status: active.

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

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2026-06-16 |
| First published | 2017-07-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=24 |
| Dependencies | 1 |
| Unpacked size | 17.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Cody Doughty |
| Maintainers | cdoughty08, charlsantony |

## Links

- npm: https://www.npmjs.com/package/cosmic-crypt
- Repository: https://github.com/CDoughty08/cosmic-crypt
- Homepage: https://github.com/CDoughty08/cosmic-crypt#readme
- Issues: https://github.com/CDoughty08/cosmic-crypt/issues
- npm.io page: https://npm.io/package/cosmic-crypt

## Dependencies (1)

- [commander](https://npm.io/package/commander.md) 15.0.0

## Recent versions

- 2.0.0 (latest) — 2026-06-16
- 1.5.2 — 2017-07-13
- 1.5.1 — 2017-07-06
- 1.5.0 — 2017-07-06
- 1.4.1 — 2017-07-05
- 1.4.0 — 2017-07-05
- 1.3.0 — 2017-07-05
- 1.2.0 — 2017-07-04
- 1.1.0 — 2017-07-03

## README

[![CI](https://github.com/CDoughty08/cosmic-crypt/actions/workflows/ci.yml/badge.svg)](https://github.com/CDoughty08/cosmic-crypt/actions/workflows/ci.yml)
[![npm version](https://badge.fury.io/js/cosmic-crypt.svg)](https://badge.fury.io/js/cosmic-crypt)

Installation
============
```
npm install cosmic-crypt
```

Anytime the version of of this package changes the HMAC signatures will be invalid when decrypting. Either lock the version to what you need, or re-encrypt you content with the new version, when upgrading.

Quickstart
==============

Usage is extremely simple:
```ts
import { CosmicCrypt } from './cosmic-crypt';

async function sample() {
    const credentials = await CosmicCrypt.generateCredentials();

    const plainText = Buffer.from('Some sample data');

    const sampleEncrypted = await CosmicCrypt.encrypt(plainText, credentials);

    const sampleDecrypted = await CosmicCrypt.decrypt(sampleEncrypted, credentials.password);

    console.log(`${sampleEncrypted.toString()}`);
    console.log(`${plainText.toString()} === ${sampleDecrypted.toString()}`);
}

sample();
```

Expectations
============
This utility makes a few assumptions about what you want to do, as it was made for a simple purpose. It currently does not provide a large feature set.

Cipher text is encrypted and return as `hex`

The cipher algorithm is currently locked to `aes-256-cbc`

The IV must be 128 bit, 16 bytes.

Passwords must be 64 bytes or larger.

The Salt must be 32 bytes.

pbkdf2 iterations defaults to 10000.

Supplied Error Codes
====================
```ts
enum EncryptErrorCode {
  PASSWORD_TOO_SHORT,
  IV_INVALID_LENGTH,
  SALT_INVALID_LENGTH
}

enum DecryptErrorCode {
  AUTHENTICATION_ERROR
}

// Unpack is part of the decrypt process
enum UnpackErrorCode {
  INVALID_META_LENGTH,
  INVALID_ENCRYPTED_DATA
}
```

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