# @dkh-dev/crypto

> A crypto library that is easy to use and hard to misuse

Latest version **4.0.0** (published 2020-10-21) · ISC license · 0 weekly downloads

## Install

```sh
npm install @dkh-dev/crypto
pnpm add @dkh-dev/crypto
yarn add @dkh-dev/crypto
bun add @dkh-dev/crypto
```

## 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 | 4.0.0 |
| Published | 2020-10-21 |
| First published | 2019-09-09 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 14.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Hoang |
| Maintainers | dkh-dev |
| Keywords | crypto, scrypt, encrypt, decrypt, hash, hmac, sha, sha256, aes, aes256 |

## Links

- npm: https://www.npmjs.com/package/@dkh-dev/crypto
- Repository: https://github.com/dkh-dev/crypto
- Homepage: https://github.com/dkh-dev/crypto#readme
- Issues: https://github.com/dkh-dev/crypto/issues
- npm.io page: https://npm.io/package/@dkh-dev/crypto

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

- 4.0.0 (latest) — 2020-10-21
- 3.4.0 — 2020-10-09
- 3.3.0 — 2020-08-26
- 3.2.2 — 2020-06-10
- 3.2.1 — 2020-06-10
- 3.2.0 — 2020-06-09
- 3.1.0 — 2020-06-06
- 2.0.0 — 2019-09-20
- 1.1.0 — 2019-09-10
- 1.0.0 — 2019-09-09

## README

# [@dkh-dev/crypto](https://www.npmjs.com/package/@dkh-dev/crypto)

_A crypto library that is easy to use and hard to misuse_

## Installation

```bash
$ yarn add @dkh-dev/crypto
```

## Examples

### Scrypt

```javascript
'use strict'

const { scrypt } = require('@dkh-dev/crypto')

const main = async () => {
  const data = 'data'
  const password = 'password'

  const hash = await scrypt.hash(password, data)

  console.log(hash.toString('base64'))
  console.log(await scrypt.verify(password, data, hash))
  // => DggBZexpdHVfTclOZY+wiL5DN24ceOFgs2BX3e48CKU/MMKvVUb0MSV3+vGR7zHBtU3hx3f+ryFcgGHqY8GH0r4z6Q==
  //    true
}

main()
```

### AES-256-GCM

```javascript
'use strict'

const { aes256 } = require('@dkh-dev/crypto')

const data = 'data'
const password = 'secret'

const main = async () => {
  const encrypted = await aes256.encrypt(password, data)
  const decrypted = await aes256.decrypt(password, encrypted)

  console.log(encrypted.toString('base64'))
  console.log(decrypted.toString('utf8') === data)
  // => qR1XbghwPYq+iR6rxXdygeZ7mhWYQbWr2rEIr5R9WYJQMU2rAtz95J3OhJAunkmeDex9RA==
  //    true
}

main()
```

### HMAC-SHA256

```javascript
'use strict'

const { hmac } = require('@dkh-dev/crypto')

const data = 'data'
const key = 'secret'

const main = async () => {
  const buffer = await hmac.sha256(key, data)

  console.log(buffer.toString('base64'))
  // => GywWt1vSqHDBFBU8zaW8/KYzFLxyL6Fg1pDeEzzLuds=
}

main()
```

### SHA256

```javascript
'use strict'

const { hash } = require('@dkh-dev/crypto')

const data = 'data'
const key = 'secret'

const main = async () => {
  const buffer = await hash.sha256(key, data)

  console.log(buffer.toString('base64'))
  // => Om6weQ85rIfJTzhWst0sXREOaBFgImGpqSPTuyOtyLc=
}

main()
```

### Random bytes

```javascript
'use strict'

const { randomBytes } = require('@dkh-dev/crypto')

const main = async () => {
  console.log(await randomBytes(3))
  // => <Buffer 86 70 d6>
}

main()
```

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