# symcryptor

> SymCryptor allows you to easy use a symmetric encryption (with AES-CTR-256) and a signature method (with KMAC-256)

Latest version **1.0.2** (published 2022-12-12) · GPL-3.0-or-later license · 0 weekly downloads

## Install

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

## Health

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

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

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2022-12-12 |
| First published | 2022-11-03 |
| Weekly downloads | 0 |
| License | GPL-3.0-or-later |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 42.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | angy91m |
| Maintainers | angy91m |
| Keywords | crypto, cryptography, encryption, decryption, encrypt, decrypt, cipher, aes, ctr, aes-256-ctr, hash, sha3, kmac, kmac256 |

## Links

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

## Dependencies (1)

- [js-sha3](https://npm.io/package/js-sha3.md) ^0.8.0

## 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.0.2 (latest) — 2022-12-12
- 1.0.1 — 2022-11-03
- 1.0.0 — 2022-11-03
- 0.9.1 — 2022-11-03

## README

# SymCryptor

SymCryptor allows you to easy use a symmetric encryption (with AES-CTR-256) and a signature method (with KMAC-256)

## Installation

```bash
npm i symcryptor
```

## Test
```bash
npm test
```

## Usage

```javascript
const symCryptor = require( 'symcryptor' );
( async () => {
    const clearText = 'Hello world!';

    // For hashing
    const hashSecret = await symCryptor.rndBytes( 32 ); // Return a random 256-bit Buffer
    const digest = symCryptor.getHmac( clearText, hashSecret ); // Return a 512-bit Buffer as digest

    // For encryption
    const key = await symCryptor.rndBytes( 32 ); // Key must be a Buffer or Uint8Array of 512-bit
    const encrypted = await symCryptor.encrypt( clearText, key, hashSecret ); // Return a Buffer

    // For decryption
    const decrypted = await symCryptor.decrypt( clearText, key, hashSecret ); // Return a Buffer
} )();
```

## Methods

### `symCryptor.rndBytes`
```javascript
symCryptor.rndBytes( length: Number [, bytes: Boolean = false] )
```

#### Parameters

* `length` Required - The length of random data in bytes
* `bytes` Optional - If `true` return `Uint8Array` instead of `Buffer` on fulfillment

#### Return

Random `Buffer | Uint8Array` of selected length when `Promise` resolved else throw an `Error`

### `symCryptor.getHmac`
```javascript
symCryptor.getHmac( data: String | Buffer | Uint8Array, key: Buffer | Uint8Array [, customization: String | Buffer | Uint8Array = '' [, bytes: Boolean = false]] )
```

#### Parameters

* `data` Required - The data you want hash
* `key` Required - The secret key (it should be of 256-bit)
* `customization` Optional - Some data you want to pass to hash algorithm (like AAD in AES-GCM)
* `bytes` Optional - If `true` return `Uint8Array` instead of `Buffer`

#### Return

A 512-bit `Buffer | Uint8Array` as digest else throw an `Error`

### `symCryptor.encrypt`
```javascript
symCryptor.encrypt( data: String | Buffer | Uint8Array, key: Buffer | Uint8Array [, hashKey: Buffer | Uint8Array [, customization: String | Buffer | Uint8Array = '' [, bytes: Boolean = false]]] )
```

#### Parameters

* `data` Required - The data you want to encrypt
* `key` Required - The key you want to use for encryption (it must be of 256-bit)
* `hashKey` Optional - The key you want to use to sign encrypted data
* `customization` Optional - Some data you want to pass to hash algorithm (like AAD in AES-GCM)
* `bytes` Optional - If `true` return `Uint8Array` instead of `Buffer` on fulfillment

#### Return

`Buffer | Uint8Array` when `Promise` resolved else throw an `Error`

### `symCryptor.decrypt`
```javascript
symCryptor.decrypt( data: Buffer | Uint8Array, key: Buffer | Uint8Array [, hashKey: Buffer | Uint8Array [, customization: String | Buffer | Uint8Array = '' [, bytes: Boolean = false]]] )
```

#### Parameters

* `data` Required - The encrypted data you want to decrypt
* `key` Required - The key you have to use for decryption (it must be of 256-bit)
* `hashKey` Optional - The key you have to use to verify signature of encrypted data (required if data was signed)
* `customization` Optional - Some data you have to pass to hash algorithm (like AAD in AES-GCM; required if it was passed during encryption)
* `bytes` Optional - If `true` return `Uint8Array` instead of `Buffer` on fulfillment

#### Return

`Buffer | Uint8Array` when `Promise` resolved else throw an `Error`

## Note
* IV and signature are automatically added to encrypted data and removed when data will be decrypted

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