# kruptein

> crypto; from kruptein to hide or conceal

Latest version **3.4.0** (published 2026-06-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install kruptein
pnpm add kruptein
yarn add kruptein
bun add kruptein
```

## Health

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

Positive: no vulnerabilities; high maintenance score.

Warnings: low downloads; no types; no esm support.

## Facts

| | |
|---|---|
| Version | 3.4.0 |
| Published | 2026-06-21 |
| First published | 2019-03-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=18 |
| Dependencies | 2 |
| Unpacked size | 36.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 8 |
| Author | Jason Gerfen |
| Maintainers | jas- |
| Keywords | crypto, cryptography, cryptr, crypter, encryption, decryption, encrypt, decrypt, AES, GCM, authenticated, authenticate, unicode, symmetric, cipher, argon2, scrypt, pbkdf2, security, asn.1 |

## Links

- npm: https://www.npmjs.com/package/kruptein
- Repository: https://github.com/jas-/kruptein
- Homepage: https://github.com/jas-/kruptein#readme
- Issues: https://github.com/jas-/kruptein/issues
- npm.io page: https://npm.io/package/kruptein

## Dependencies (2)

- [kruptein](https://npm.io/package/kruptein.md) ^3.3.0
- [@jas-/asn.1](https://npm.io/package/@jas-/asn.1.md) >=5

## 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

- 3.4.0 (latest) — 2026-06-21
- 3.3.0 — 2026-03-23
- 3.2.1 — 2026-02-24
- 3.2.0 — 2026-02-12
- 3.1.7 — 2025-12-12
- 3.1.6 — 2025-12-12
- 3.1.5 — 2025-12-11
- 3.1.4 — 2025-11-19
- 3.1.3 — 2025-11-19
- 3.1.2 — 2025-11-18
- 3.1.1 — 2025-11-18
- 3.1.0 — 2025-11-18
- 3.0.9 — 2025-11-18
- 3.0.8 — 2025-06-06
- 3.0.7 — 2024-08-13
- … 39 more at https://npm.io/package/kruptein/versions

## README

🔐 kruptein 
========
crypto (krip-toh); from `kruptein` to hide or conceal.

[![npm](https://img.shields.io/npm/v/kruptein.svg)](https://npmjs.com/package/kruptein)
![Downloads](https://img.shields.io/npm/dm/kruptein.svg)
[![Known Vulnerabilities](https://snyk.io/test/github/jas-/kruptein/badge.svg)](https://snyk.io/test/github/jas-/kruptein)
![Build Status](https://github.com/jas-/kruptein/actions/workflows/node.js.yml/badge.svg)


🔬 Sandbox
-------
 Here you can experiment with the module to ensure it will suit your needs. [kruptein @ codesandbox.io](https://codesandbox.io/p/devbox/romantic-wu-cywk2c)


🔒 Encrypt
-----------------
Encrypt a plaintext message using the default options.

```javascript
const kruptein = require("kruptein")();
const secret = "S3cre+_Squ1rr3l";
const plaintext = "Some kind of wonderfully private message";

kruptein.set(secret, plaintext, (error, ciphertext) => {
  if (error) {
    throw new Error(error);
  }

  console.log(ciphertext);
});
```


🔓 Decrypt
------------------
Decrypt a ciphertext returned by `kruptein.set()` using the same secret.

```javascript
const kruptein = require("kruptein")();
const secret = "S3cre+_Squ1rr3l";
const ciphertext = "<ciphertext returned by kruptein.set()>";

kruptein.get(secret, ciphertext, (error, plaintext) => {
  if (error) {
    throw new Error(error);
  }

  console.log(plaintext);
});
```


📦 Install
-------
To install `npm install kruptein`


👓 Methods
-------
*   `.set(secret, plaintext, [aad], callback)`
*   `.get(secret, ciphertext, [{at: auth_tag, aad: aad}], callback)`


🛠️ Options
-------
Industry standards are used for the algorithm, hashing algorithm, key & IV sizes.
The default key derivation function is `pbkdf2`, however use of the `scrypt` or `argon2` can be used as well.

#### Cryptography options
*   `algorithm`: (Optional) Cipher algorithm from `crypto.getCiphers()`. Default: `aes-256-gcm`.
*   `hashing`: (Optional) Hash algorithm from `crypto.getHashes()`. Default: `sha384`.
*   `key_size`: (Optional) Key size bytes (should match block size of algorithm). Default: `32`
*   `iv_size`: (Optional) IV size bytes. Default: `16`.
*   `at_size`: (Optional) Authentication tag size. Applicable to `gcm` & `ocb` cipher modes. Default: `128`.

#### Key derivation options
*   `use_scrypt`: (Optional) Use `.scrypt()` to derive a key. Requires node > v10. Default/Fallback: `.pbkdf2()`.
*   `use_argon2`: (Optional) Use `.argon2id()` to derive a key. Requires node > v24. Default/Fallback: `.pbkdf2()`.

#### Encoding options
*   `encodeas`: (Optional) Output encoding. Currently supports `binary`, `hex`, & `base64`. Default: `base64`.
*   `use_asn1`: (Optional) Disable the default ASN.1 encoding. Default: true


📐 Options example
-----------------
An example of creating a new ciphertext object.

```javascript
const opts = {
  algorithm: 'aes-256-gcm',
  hashing: 'sha384',
  key_size: 64,
  iv_size: 16,
  at_size: 128,
  use_argon2: true,
  encodeas: 'base64',
  use_asn1: true
}

const kruptein = require("kruptein")(opts || {});
```


🗝️ Usage
-----
When selecting an algorithm from `crypto.getCiphers()` the `iv` and `key_size` values are calculated auto-magically to make implementation easy.

You can always define your own if the defaults per algorithm and mode aren't what you would like; see the `options` section above.

The `secret` must meet [complexity requirements](https://github.com/jas-/kruptein/blob/5d41a5fa35101112f150c6bf3f757d660f0f3ce1/lib/kruptein.js#L401)


🌱 Output
------
The `.set()` method output depends on three factors; the `encodeas`, `algorithm` and `use_asn1`.

For any algorithm that supports authentication (AEAD), the object structure includes the `Authentication Tag` and the `Additional
Authentication Data` attribute and value.

When the `use_asn1` option is enabled (default is true), the result is an [ASN.1](https://letsencrypt.org/docs/a-warm-welcome-to-asn1-and-der/) value using the `encodeas` value. While this is a more complex encoding option, it helps standardize & minimize the size of the resulting ciphertext output.


🧪 Test harness
------------
The included test harness, invoked with `npm test`, makes every attempt to trap and handle errors. Some of which come from side channel or possible malability of the resultant ciphertext.

This can be seen within the `test/index.js` CI test harness under the HMAC, AT & AAD validation test cases.

📊 Benchmark harness
------------
Run `npm run bench` for a human-readable benchmark report or `npm run bench:json` for JSON output.

The benchmark measures per-case wall time, CPU, memory, process disk I/O and, when available, GPU telemetry.


🧠 References
-----------------------
This module conforms to industry recommendations regarding algorithm type, mode, key size, iv size & implementation, digests, key  derivation & management etc. References used provided here:

**RFC:**
*   [RFC 2104](https://tools.ietf.org/html/rfc2104): HMAC: Keyed-Hashing for Message Authentication
*   [RFC 4086](https://tools.ietf.org/html/rfc4086): Randomness Requirements for Security
*   [RFC 5084](https://tools.ietf.org/html/rfc5084): Using AES-CCM and AES-GCM Authenticated Encryption
*   [RFC 7914](https://tools.ietf.org/html/rfc7914): The scrypt Password-Based Key Derivation Function
*   [RFC 8018](https://tools.ietf.org/html/rfc8018): Password-Based Cryptography Specification
*   [RFC 9106](https://datatracker.ietf.org/doc/html/rfc9106): Argon2 Memory-Hard Function for Password Hashing and Proof-of-Work Applications
*   [X.697](https://www.itu.int/rec/T-REC-X.697-201710-I/en): ASN.1 encoding rules: Specifications of JavaScript Object Notation Encoding Rules (JER)


**NIST:**
*   [SP 800-38A](https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38a.pdf): Block cipher modes of operation
*   [SP 800-38B](https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38d.pdf): Recommendation for Block Cipher Modes of Operation: Galois/Counter Mode (GCM) and GMAC
*   [SP 800-57P1](https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-57pt1r4.pdf): Recommendations for key management
*   [SP 800-107](https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-107r1.pdf): Recommendation for Applications Using Approved Hash Algorithms
*   [SP 800-108](https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-108.pdf): Recommendation for Key Derivation Using Pseudorandom Functions
*   [SP 800-131A](https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-131Ar2.pdf): Transitioning the Use of Cryptographic Algorithms and Key Lengths
*   [SP 800-132](https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-132.pdf): Recommendation for Password-Based Key Derivation
*   [SP 800-175B](https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-175B.pdf): Guideline for Using Cryptographic Standards in the Federal Government


**FIPS:**
*   [FIPS 197](https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.197.pdf): Advanced Encryption Standard (AES)
*   [FIPS 198-1](https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.198-1.pdf): The Keyed-Hash Message Authentication Code (HMAC)
*   [FIPS 180-4](https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf): Secure Hash Standard (SHS)
*   [FIPS 186-5](https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.186-5.pdf): Digital Signature Standard (DSS)


📡 Contributing
------------
Contributions are welcome & appreciated!

Refer to the [contributing document](https://github.com/jas-/kruptein/blob/master/CONTRIBUTING.md) to help facilitate pull requests.


📑 License
-------
This software is licensed under the [MIT License](https://github.com/jas-/kruptein/blob/master/LICENSE).

Copyright Jason Gerfen, 2019.

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