JSPM

@sequencemedia/crypto

1.1.5
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 502
  • Score
    100M100P100Q94471F
  • License ISC

Package Exports

  • @sequencemedia/crypto

Readme

@sequencemedia/crypto

Encrypt and decrypt in Node and Bash

Node

Exports two functions, encrypt and decrypt

import {
  encrypt,
  decrypt
} from '@sequencemedia/crypto'

encrypt

function encrypt(buffer: Buffer, secret: string, bytes?: number, algorithm?: string): Buffer

Only buffer and secret are required

  • buffer is the data to encrypt
  • secret is the secret key to use for encryption

Both bytes and algorithm are optional

  • bytes is the number of random bytes to use for the encryption initialisation vector. The default is 16
  • algorithm is the algorithm to use for encryption. The default is aes-256-ctr

decrypt

function decrypt(buffer: Buffer, secret: string, bytes?: number, algorithm?: string): Buffer

Only buffer and secret are required

  • buffer is the data to decrypt
  • secret is the secret key to use for decryption

Both bytes and algorithm are optional

  • bytes is the number of bytes to slice from the buffer for the decryption initialisation vector. The default is 16
  • algorithm is the algorithm to use for decryption. The default is aes-256-ctr

Bash

Exports two functions, encrypt and decrypt

source ./crypto.sh

encrypt

Requires CRYPTO_KEY as a variable in the Bash environment and a file path to encrypt

encrypted_file_data=$(encrypt "./file.txt")
encrypt "./file.txt" > "./encrypted.txt"

decrypt

Requires CRYPTO_KEY as a variable in the Bash environment and a file path to decrypt

file_data=$(decrypt "./encrypted.txt")
decrypt "./encrypted.txt" > "./file.txt"

Bash utilities

encrypt.sh

Requires CRYPTO_KEY as a variable in the Bash environment

  • A file origin path for data to encrypt
  • A file destination path to put the encrypted data
CRYPTO_KEY='secret' ./encrypt.sh --origin "./file.txt" --destination "./encrypted.txt"

decrypt.sh

Requires CRYPTO_KEY as a variable in the Bash environment

  • A file origin path for data to decrypt
  • A file destination path to put the decrypted data
CRYPTO_KEY='secret' ./decrypt.sh --origin "./encrypted.txt" --destination "./file.txt"