Package Exports
- @sequencemedia/crypto
- @sequencemedia/crypto/src/index.mjs
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 (@sequencemedia/crypto) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
@sequencemedia/crypto
Encrypt and decrypt in Node and Bash
Node
The package main exports two functions, encrypt and decrypt
import {
encrypt,
decrypt
} from '@sequencemedia/crypto'encrypt
function encrypt(
buffer: Buffer,
secret: string,
bytes?: number,
algorithm?: string
): BufferOnly buffer and secret are required
bufferis the data to encryptsecretis the secret key to use for encryption
Both bytes and algorithm are optional
bytesis the number of random bytes to use for the encryption initialisation vector. The default is16algorithmis the algorithm to use for encryption. The default isaes-256-ctr
decrypt
function decrypt(
buffer: Buffer,
secret: string,
bytes?: number,
algorithm?: string
): BufferOnly buffer and secret are required
bufferis the data to decryptsecretis the secret key to use for decryption
Both bytes and algorithm are optional
bytesis the number of bytes to slice from the buffer for the decryption initialisation vector. The default is16algorithmis the algorithm to use for decryption. The default isaes-256-ctr
Bash
The package contains three scripts
crypto.shencrypt.shdecrypt.sh
Script crypto.sh exports four functions to consume in your own Bash scripts
source ./crypto.shencryptdecryptencrypt_directorydecrypt_directory
Scripts encrypt.sh and decrypt.sh can be executed at the command line
Bash functions
encrypt
Requires CRYPTO_KEY as a variable in the Bash environment and a file path to encrypt
CRYPTO_KEY='secret'
encrypted_file_data=$(encrypt "./file.txt")CRYPTO_KEY='secret'
encrypt "./file.txt" > "./encrypted.txt"decrypt
Requires CRYPTO_KEY as a variable in the Bash environment and a file path to decrypt
CRYPTO_KEY='secret'
file_data=$(decrypt "./encrypted.txt")CRYPTO_KEY='secret'
decrypt "./encrypted.txt" > "./file.txt"encrypt_directory
Requires CRYPTO_KEY as a variable in the Bash environment and a directory path to encrypt
- The first argument is the origin directory of files to encrypt
- The second argument is the destination directory for the encrypted files
CRYPTO_KEY='secret'
encrypt_directory "./directory" "./encrypted"decrypt_directory
Requires CRYPTO_KEY as a variable in the Bash environment and a directory path to decrypt
- The first argument is the origin directory of files to decrypt
- The second argument is the destination directory for the decrypted files
CRYPTO_KEY='secret'
decrypt_directory "./encrypted" "./directory"Bash scripts
encrypt.sh
Requires CRYPTO_KEY as a variable in the Bash environment
- You can provide either file or directory paths
- You can provide
--verboseor-v
File paths
- A file origin path to encrypt
- A file destination path for the encrypted file
CRYPTO_KEY='secret' ./encrypt.sh \
--origin "./file.txt" \
--destination "./encrypted.txt"Directory paths
- A directory origin path to encrypt
- A directory destination path for encrypted files
CRYPTO_KEY='secret' ./encrypt.sh \
--origin "./directory" \
--destination "./encrypted"decrypt.sh
Requires CRYPTO_KEY as a variable in the Bash environment
- You can provide either file or directory paths
- You can provide
--verboseor-v
File paths
- A file origin path to decrypt
- A file destination path for the decrypted file
CRYPTO_KEY='secret' ./decrypt.sh \
--origin "./encrypted.txt" \
--destination "./file.txt"Directory paths
- A directory origin path to decrypt
- A directory destination path for decrypted files
CRYPTO_KEY='secret' ./decrypt.sh \
--origin "./encrypted" \
--destination "./directory"