New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@dkh-dev/crypto

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dkh-dev/crypto

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

latest
Source
npmnpm
Version
4.0.0
Version published
Maintainers
1
Created
Source

@dkh-dev/crypto

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

Installation

$ yarn add @dkh-dev/crypto

Examples

Scrypt

'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

'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

'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

'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

'use strict'

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

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

main()

Keywords

crypto

FAQs

Package last updated on 21 Oct 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts