# cpass

![NPM](https://camo.githubusercontent.com/eea79c8f8fd0cec826a479459e3d18910b481d63/68747470733a2f2f6e6f6465692e636f2f6e706d2f63706173732e706e673f6d696e693d7472756526646f776e6c6f6164733d7472756526646f776e6c6f616452616e6b3d747275652673746172733d74727565)

[![npm version](https://camo.githubusercontent.com/6c6b76def75163239fc4897567a76cdecfadbc8c/68747470733a2f2f62616467652e667572792e696f2f6a732f63706173732e737667)](https://badge.fury.io/js/cpass) [![Downloads](https://camo.githubusercontent.com/f77a26f989906e854ac166f82eb58f1d71c8df47/68747470733a2f2f696d672e736869656c64732e696f2f6e706d2f646d2f63706173732e737667)](https://www.npmjs.com/package/cpass) [![Build Status](https://camo.githubusercontent.com/9e84f9a05f4aa725a109da990eb6a8ed71ce59b4/68747470733a2f2f6465762e617a7572652e636f6d2f6b6f6c7479616b6f762f53504e6f64652f5f617069732f6275696c642f7374617475732f63706173733f6272616e63684e616d653d6d6173746572)](https://dev.azure.com/koltyakov/SPNode/_build/latest?definitionId=5\&branchName=master)

> Encrypts password to some sort of a 'secure string' to be stored in text configs to reduce risks of a silly leak.

Decripts a 'secure string' to plain password.

### Installation

```
npm install cpass
```

### Usage

#### JavaScript

```typescript
const Cpass = require('cpass').Cpass;

const cpass = new Cpass();

const password = 'password';

const secured = cpass.encode(password);
// secured: "40bbb043608f54d....MhKghXTcaR2A//yNXg==" 
// is unique on different machines

const unsecured = cpass.decode(secured);
// unsecured: 'password'
```

#### TypeScript

```typescript
import { Cpass } from 'cpass';

const cpass = new Cpass();

const password = 'password';

const secured = cpass.encode(password);
// secured: "40bbb043608f54d....MhKghXTcaR2A//yNXg=="
// is unique on different machines

const unsecured = cpass.decode(secured);
// unsecured: 'password'
```

Decoding plain text will return it back:

```typescript
const plainText = 'plain (not encoded text)';
const decodedText = cpass.decode(plainText);
// decodedText: 'plain (not encoded text)'
// plainText === decodedText
```

#### Encryption with master key

```typescript
import { Cpass } from 'cpass';
const cpass = new Cpass('MasterKey');
```

### Tests

#### Local run

```
npm run test
```

#### Run in Docker for specific Node.js version

```bash
# Build an image
docker build -f ./docker/Dockerfile.node8 -t cpass.node8 .
# Run tests
docker run cpass.node8
```

### Comments

This module is not for a real security purposes. Just for 'dummy hackers' secure and minifying risks of any password storage in a plain form.

Once encoded, the password secured form can be decoded only on the same machine, but the logic behind this is very straightforward.
