0.6.2 • Published 19 days ago

@autotelic/envelope-encryptor v0.6.2

Weekly downloads
-
License
MIT
Repository
github
Last release
19 days ago

envelope-encryptor

Envelope encryption with configurable KMS.

Installation

npm install @autotelic/envelope-encryptor

Usage

// Using AWS KMS
import { createEnvelopeEncryptor, awsKms } from '@autotelic/envelope-encryptor'

const {
  AWS_REGION,
  KMS_KEY_ID,
  KMS_ACCESS_KEY_ID,
  KMS_SECRET_ACCESS_KEY
} = process.env

const keyService = awsKms(KMS_KEY_ID, {
  region: AWS_REGION,
  credentials: {
    accessKeyId: KMS_ACCESS_KEY_ID,
    secretAccessKey: KMS_SECRET_ACCESS_KEY
  }
})

const encryptor = createEnvelopeEncryptor(keyService)

const { encrypt, decrypt } = encryptor

// encrypt; store these in the db; plaintext is encrypted at rest
const {
  ciphertext,
  key,
  salt
 } = await encrypt('plaintext')

// decrypt
const plaintext = await decrypt({
  ciphertext: ciphertext.toString(),
  key,
  salt
})

In development and testing

Don't need to use a real KMS, so export

0.6.2

19 days ago

0.6.1

19 days ago

0.5.0

27 days ago

0.5.1

27 days ago

0.3.0

2 months ago

0.4.1

2 months ago

0.2.1

2 months ago

0.2.0

2 months ago

0.0.2

3 years ago

0.0.1

3 years ago