JSPM

simple-kms-cryptor

1.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • 0
  • Score
    100M100P100Q31380F
  • License Apache-2.0

Simple KMS Cryptor

Package Exports

  • simple-kms-cryptor

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (simple-kms-cryptor) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Simple KMS Cryptor

Simple cryptor library for encrypting object using AWS KMS key

Build Status

Usage Example

Prepare the config

The config is compatible directly with the AWS.KMS options as specified here:

Example of config:

let config = {
    region: '<your aws region here>',
    accessKeyId: '<your aws access key id here>',
    secretAccessKey: '<your aws secret access key>',
    kms: {
        KeyId: '<kms key ARN or KeyId>',
    }
}

Creating instance

const KMSCrypt = require('simple-kms-crypto');

let kmscrypt = new KMSCrypt(config);

Encrypting object

encrypt method will return a promise

  • Encrypting plaintext to a byte array
let plaintext = 'secret text';
kmscrypt.encrypt(plaintext)
  .then(ciphertext => {
      /*
          ciphertext will be a Buffer with holding the encrypted data as byte array
      */
  })
  .catch(err => {
      /*
          encryption failed
      */
  })
  • Encrypting plaintext to a byte array
let plaintext = 'secret text';
kmscrypt.encrypt(plaintext)
  .then(ciphertext => {
      /*
          ciphertext will be a Buffer with holding the encrypted data as byte array
      */
  })
  .catch(err => {
      /*
          encryption failed
      */
  })

Decrypting object

decrypt method will return a promise

  • If ciphertext is a byte array
kmscrypt.decrypt(ciphertext)
    .then(plaintext => {
        /*
            plaintext is decrypted object
        */    
    })
    .catch(err => {
        /*
            decryption failed
        */
    })
  • If ciphertext is base64 encoded
kmscrypt.decrypt(ciphertext, 'base64')
    .then(plaintext => {
        /*
            plaintext is decrypted object
        */    
    })
    .catch(err => {
        /*
            decryption failed
        */
    })

Methods

encrypt(plaintext, encryptionType) => Promise

  • plaintext is the object to be encrypted. Supported format: string, object, number
  • encryptionType: base64 | binary (default)

decrypt(ciphertext, cipherType) => Promise

  • ciphertext is the encrypted data formatted as binary or base64
  • cipherType is the type of ciphertext which can be base64 or binary