> For the complete documentation index, see [llms.txt](https://node.spflow.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://node.spflow.com/packages/cpass.md).

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


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://node.spflow.com/packages/cpass.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
