1.2.179 • Published 1 day ago

@sequencemedia/crypto v1.2.179

Weekly downloads
-
License
ISC
Repository
github
Last release
1 day ago

@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
): 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

The package contains three scripts

  1. crypto.sh
  2. encrypt.sh
  3. decrypt.sh

Script crypto.sh exports four functions to consume in your own Bash scripts

source ./crypto.sh
  1. encrypt
  2. decrypt
  3. encrypt_directory
  4. decrypt_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 --verbose or -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 --verbose or -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"
1.2.179

1 day ago

1.2.178

3 days ago

1.2.177

8 days ago

1.2.176

9 days ago

1.2.175

10 days ago

1.2.174

17 days ago

1.2.173

22 days ago

1.2.172

23 days ago

1.2.171

25 days ago

1.2.170

28 days ago

1.2.169

29 days ago

1.2.168

1 month ago

1.2.167

1 month ago

1.2.166

1 month ago

1.2.165

1 month ago

1.2.164

1 month ago

1.2.163

1 month ago

1.2.162

2 months ago

1.2.161

2 months ago

1.2.160

2 months ago

1.2.159

2 months ago

1.2.158

2 months ago

1.2.157

2 months ago

1.2.156

2 months ago

1.2.155

2 months ago

1.2.154

2 months ago

1.2.153

2 months ago

1.2.152

2 months ago

1.2.150

2 months ago

1.2.151

2 months ago

1.2.149

2 months ago

1.2.147

3 months ago

1.2.146

3 months ago

1.2.148

3 months ago

1.2.145

3 months ago

1.2.144

3 months ago

1.2.139

3 months ago

1.2.138

3 months ago

1.2.137

3 months ago

1.2.136

3 months ago

1.2.135

3 months ago

1.2.134

3 months ago

1.2.133

3 months ago

1.2.132

3 months ago

1.2.131

3 months ago

1.2.130

3 months ago

1.2.129

4 months ago

1.2.128

4 months ago

1.2.127

4 months ago

1.2.125

4 months ago

1.2.126

4 months ago

1.2.124

4 months ago

1.2.123

4 months ago

1.2.122

4 months ago

1.2.121

4 months ago

1.2.120

4 months ago

1.2.119

4 months ago

1.2.118

4 months ago

1.2.116

4 months ago

1.2.115

4 months ago

1.2.117

4 months ago

1.2.114

5 months ago

1.2.113

5 months ago

1.2.112

5 months ago

1.2.111

5 months ago

1.2.110

5 months ago

1.2.109

5 months ago

1.2.108

5 months ago

1.2.107

5 months ago

1.2.106

5 months ago

1.2.105

5 months ago

1.2.104

5 months ago

1.2.81

6 months ago

1.2.82

6 months ago

1.2.80

6 months ago

1.2.85

6 months ago

1.2.86

6 months ago

1.2.83

6 months ago

1.2.84

6 months ago

1.2.89

6 months ago

1.2.87

6 months ago

1.2.88

6 months ago

1.2.92

6 months ago

1.2.93

6 months ago

1.2.90

6 months ago

1.2.91

6 months ago

1.2.96

6 months ago

1.2.97

5 months ago

1.2.94

6 months ago

1.2.95

6 months ago

1.2.13

11 months ago

1.2.98

5 months ago

1.2.99

5 months ago

1.2.16

10 months ago

1.2.17

10 months ago

1.2.14

11 months ago

1.2.15

10 months ago

1.2.60

8 months ago

1.2.63

8 months ago

1.2.64

7 months ago

1.2.61

8 months ago

1.2.62

8 months ago

1.2.67

7 months ago

1.2.68

7 months ago

1.2.65

7 months ago

1.2.66

7 months ago

1.2.69

7 months ago

1.2.70

7 months ago

1.2.71

7 months ago

1.2.74

7 months ago

1.2.75

7 months ago

1.2.72

7 months ago

1.2.73

7 months ago

1.2.78

7 months ago

1.2.79

7 months ago

1.2.76

7 months ago

1.2.77

7 months ago

1.2.41

9 months ago

1.2.42

9 months ago

1.2.40

9 months ago

1.2.45

8 months ago

1.2.46

8 months ago

1.2.43

8 months ago

1.2.44

8 months ago

1.2.49

8 months ago

1.2.47

8 months ago

1.2.48

8 months ago

1.2.101

5 months ago

1.2.100

5 months ago

1.2.103

5 months ago

1.2.102

5 months ago

1.2.52

8 months ago

1.2.53

8 months ago

1.2.50

8 months ago

1.2.51

8 months ago

1.2.56

8 months ago

1.2.57

8 months ago

1.2.54

8 months ago

1.2.55

8 months ago

1.2.58

8 months ago

1.2.59

8 months ago

1.2.18

10 months ago

1.2.19

10 months ago

1.2.20

10 months ago

1.2.23

10 months ago

1.2.24

10 months ago

1.2.21

10 months ago

1.2.22

10 months ago

1.2.27

10 months ago

1.2.28

10 months ago

1.2.25

10 months ago

1.2.26

10 months ago

1.2.29

10 months ago

1.2.30

9 months ago

1.2.31

9 months ago

1.2.34

9 months ago

1.2.35

9 months ago

1.2.32

9 months ago

1.2.33

9 months ago

1.2.38

9 months ago

1.2.39

9 months ago

1.2.36

9 months ago

1.2.37

9 months ago

1.2.0

11 months ago

1.2.8

11 months ago

1.2.7

11 months ago

1.2.6

11 months ago

1.2.5

11 months ago

1.2.4

11 months ago

1.2.3

11 months ago

1.2.2

11 months ago

1.2.1

11 months ago

1.1.70

11 months ago

1.1.30

1 year ago

1.1.73

11 months ago

1.1.72

11 months ago

1.1.71

11 months ago

1.1.34

1 year ago

1.1.33

1 year ago

1.1.32

1 year ago

1.1.31

1 year ago

1.1.38

1 year ago

1.1.37

1 year ago

1.1.36

1 year ago

1.1.35

1 year ago

1.1.39

1 year ago

1.1.41

1 year ago

1.1.40

1 year ago

1.2.12

11 months ago

1.1.45

12 months ago

1.1.44

1 year ago

1.2.10

11 months ago

1.1.43

1 year ago

1.2.11

11 months ago

1.1.42

1 year ago

1.1.49

12 months ago

1.1.48

12 months ago

1.1.47

12 months ago

1.1.46

12 months ago

1.1.52

12 months ago

1.1.51

12 months ago

1.1.50

12 months ago

1.1.56

12 months ago

1.1.55

12 months ago

1.1.54

12 months ago

1.1.53

12 months ago

1.1.59

12 months ago

1.1.58

12 months ago

1.1.57

12 months ago

1.1.63

12 months ago

1.1.62

12 months ago

1.1.61

12 months ago

1.2.9

11 months ago

1.1.60

12 months ago

1.1.67

12 months ago

1.1.66

12 months ago

1.1.65

12 months ago

1.1.64

12 months ago

1.1.69

11 months ago

1.1.68

11 months ago

1.1.1

1 year ago

1.1.9

1 year ago

1.1.8

1 year ago

1.1.7

1 year ago

1.1.6

1 year ago

1.1.5

1 year ago

1.1.4

1 year ago

1.1.3

1 year ago

1.1.2

1 year ago

1.1.12

1 year ago

1.1.11

1 year ago

1.1.10

1 year ago

1.1.16

1 year ago

1.1.15

1 year ago

1.1.14

1 year ago

1.1.13

1 year ago

1.1.19

1 year ago

1.1.18

1 year ago

1.1.17

1 year ago

1.1.23

1 year ago

1.1.22

1 year ago

1.1.21

1 year ago

1.1.20

1 year ago

1.1.26

1 year ago

1.1.25

1 year ago

1.1.24

1 year ago

1.0.4

1 year ago

1.0.5

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago