# iv-encrypt

> Encrypt an ascii string or an object to a base64 string

Latest version **1.2.2** (published 2018-02-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install iv-encrypt
pnpm add iv-encrypt
yarn add iv-encrypt
bun add iv-encrypt
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.2 |
| Published | 2018-02-02 |
| First published | 2018-02-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Tanmay Sathe |
| Maintainers | tanmaysathe |
| Keywords | encrypt, decrypt |

## Links

- npm: https://www.npmjs.com/package/iv-encrypt
- npm.io page: https://npm.io/package/iv-encrypt

## 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.2 (latest) — 2018-02-02
- 1.2.1 — 2018-02-02
- 1.2.0 — 2018-02-02
- 1.1.1 — 2018-02-02
- 1.0.0 — 2018-02-02

## README

# iv-encrypt
Simple encryption functions for node.js projects

[![NPM](https://nodei.co/npm/iv-encrypt.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/iv-encrypt/)

# Installation

Add it to your node.js project via:

```sh
npm install iv-encrypt --save
```

# Usage
First create an encryptor:

```js
// Create iv-encrypt object 
const enc = require('iv-encrypt');
```

To encrypt a string or an object:

```js
// Encrypt a plain string or object to an encrypted & base64 encoded string 
var encString = enc.Encrypt({FirstName: 'Tanmay Sathe'});
// Should print some random ascii characters
console.log("Encrypted string: ",encString);
```

To decrypt a string or an object:

```js
// Decrypt an encrypted string to a plain string or object
var decString = enc.Decrypt(encString);
// Should print `Decrypted object:  { FirstName: 'Tanmay Sathe' }`
console.log('Decrypted object: ',decString);
```

# Features

* Encrypt arbitrary objects, not just strings (objects are converted to/from JSON)
* Unique IV per call so no two calls should return the same result for the same input
* Simple algorithm for fastest possible encryption
* No complicated options
* Written to be easy to read

# API
The module provides two functions:

* `encryptor.Encrypt(obj)` - Encrypt the object and return back the encrypted cipher text. The object is first converted to text via `JSON.stringify(...)`. This means you can encrypt arbitrary objects.
* `encryptor.Decrypt(cipherText)` - Decrypts the cipher text and returns the original object. Specifically, it decrypts the cipher text and calls `JSON.parse(...)` on the result. If an error occurs during the decryption then null is returned. __Note:__ This function never throws an error for bad input, it just returns `null`.


# Internals
Interally this module uses the pure javascript algorithm for encryption. It then uses the crypto module of node.js to create an iv (intialization vector) buffer. Encryption is done by XORing with a randomly offsetted IV (intialization vector) buffer per call that is returned as part of the result.

# Dependencies
No dependencies! It uses crypto module which is built into node.js core.

# License
This plugin is released under the MIT license. See the file [LICENSE](LICENSE).

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