@sequencemedia/crypto 1.0.5 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.gitattributes ADDED
@@ -0,0 +1,15 @@
1
+ # Default behavior
2
+ * text=auto
3
+
4
+ # LF line endings
5
+ *.json text eol=lf
6
+ *.mjs text eol=lf
7
+ *.cjs text eol=lf
8
+ *.mts text eol=lf
9
+ *.sh text eol=lf
10
+ .editorconfig text eol=lf
11
+ .eslintignore text eol=lf
12
+ .eslintrc text eol=lf
13
+ .gitattributes text eol=lf
14
+ .gitignore text eol=lf
15
+ .husky/* text eol=lf
package/decrypt.sh ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+
3
+ decrypt () {
4
+ node ./src/shell/decrypt.mjs < "$1"
5
+ }
6
+
7
+ export -f decrypt
package/encrypt.sh ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+
3
+ encrypt () {
4
+ node ./src/shell/encrypt.mjs < "$1"
5
+ }
6
+
7
+ export -f encrypt
package/lib/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.decrypt=decrypt;exports.encrypt=encrypt;exports.hashKey=hashKey;var _crypto=_interopRequireDefault(require("crypto"));function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj};}function hashKey(key){if(!key)throw new Error('A key is required');return _crypto.default.createHash('sha256').update(key).digest('base64').substr(0,32);}function encrypt(buffer,key,algorithm='aes-256-ctr'){const iv=_crypto.default.randomBytes(16);const cipher=_crypto.default.createCipheriv(algorithm,hashKey(key),iv);return Buffer.concat([iv,cipher.update(buffer),cipher.final()]);}function decrypt(buffer,key,algorithm='aes-256-ctr'){const iv=buffer.slice(0,16);const decipher=_crypto.default.createDecipheriv(algorithm,hashKey(key),iv);return Buffer.concat([decipher.update(buffer.slice(16)),decipher.final()]);}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.decrypt=decrypt;exports.encrypt=encrypt;exports.hashKey=hashKey;var _crypto=_interopRequireDefault(require("crypto"));function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj};}function hashKey(key){if(!key)throw new Error('A key is required');return _crypto.default.createHash('sha256').update(key).digest('base64').substring(0,32);}function encrypt(buffer,key,bytes=16,algorithm='aes-256-ctr'){const iv=_crypto.default.randomBytes(bytes);const cipher=_crypto.default.createCipheriv(algorithm,hashKey(key),iv);return Buffer.concat([iv,cipher.update(buffer),cipher.final()]);}function decrypt(buffer,key,bytes=16,algorithm='aes-256-ctr'){const iv=buffer.slice(0,bytes);const decipher=_crypto.default.createDecipheriv(algorithm,hashKey(key),iv);return Buffer.concat([decipher.update(buffer.slice(bytes)),decipher.final()]);}
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ "use strict";var _crypto=require("@sequencemedia/crypto");const{env:{CRYPTO_KEY}={},stdout,openStdin}=process;let collector=Buffer.from('');openStdin().on('data',buffer=>{collector=Buffer.concat([collector,buffer]);}).on('end',()=>{stdout.write((0,_crypto.decrypt)(collector,CRYPTO_KEY));});
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ "use strict";var _crypto=require("@sequencemedia/crypto");const{env:{CRYPTO_KEY}={},stdout,openStdin}=process;let collector=Buffer.from('');openStdin().on('data',buffer=>{collector=Buffer.concat([collector,buffer]);}).on('end',()=>{stdout.write((0,_crypto.encrypt)(collector,CRYPTO_KEY));});
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "@sequencemedia/crypto",
3
- "version": "1.0.5",
3
+ "version": "1.1.2",
4
4
  "main": "./lib/index.cjs",
5
5
  "type": "module",
6
+ "types": "./crypto.d.ts",
6
7
  "author": {
7
8
  "name": "Jonathan Perry for Sequence Media Limited",
8
9
  "email": "sequencemedia@sequencemedia.net",
@@ -25,18 +26,19 @@
25
26
  "prepare": "husky install"
26
27
  },
27
28
  "devDependencies": {
28
- "@babel/cli": "^7.19.3",
29
- "@babel/core": "^7.20.2",
30
- "@babel/eslint-parser": "^7.19.1",
31
- "@babel/preset-env": "^7.20.2",
32
- "@sequencemedia/hooks": "^1.0.273",
33
- "core-js": "^3.26.1",
34
- "eslint": "^8.28.0",
29
+ "@babel/cli": "^7.21.0",
30
+ "@babel/core": "^7.21.4",
31
+ "@babel/eslint-parser": "^7.21.3",
32
+ "@babel/preset-env": "^7.21.4",
33
+ "@sequencemedia/hooks": "^1.0.386",
34
+ "@types/node": "^18.15.11",
35
+ "core-js": "^3.30.1",
36
+ "eslint": "^8.38.0",
35
37
  "eslint-config-standard": "^17.0.0",
36
- "eslint-plugin-import": "^2.26.0",
38
+ "eslint-plugin-import": "^2.27.5",
37
39
  "eslint-plugin-node": "^11.1.0",
38
40
  "eslint-plugin-promise": "^6.1.1",
39
- "husky": "^8.0.2"
41
+ "husky": "^8.0.3"
40
42
  },
41
43
  "exports": {
42
44
  "import": "./src/index.mjs",
package/src/index.mjs CHANGED
@@ -3,17 +3,17 @@ import crypto from 'crypto'
3
3
  export function hashKey (key) {
4
4
  if (!key) throw new Error('A key is required')
5
5
 
6
- return crypto.createHash('sha256').update(key).digest('base64').substr(0, 32)
6
+ return crypto.createHash('sha256').update(key).digest('base64').substring(0, 32)
7
7
  }
8
8
 
9
- export function encrypt (buffer, key, algorithm = 'aes-256-ctr') {
10
- const iv = crypto.randomBytes(16)
9
+ export function encrypt (buffer, key, bytes = 16, algorithm = 'aes-256-ctr') {
10
+ const iv = crypto.randomBytes(bytes)
11
11
  const cipher = crypto.createCipheriv(algorithm, hashKey(key), iv)
12
12
  return Buffer.concat([iv, cipher.update(buffer), cipher.final()])
13
13
  }
14
14
 
15
- export function decrypt (buffer, key, algorithm = 'aes-256-ctr') {
16
- const iv = buffer.slice(0, 16)
15
+ export function decrypt (buffer, key, bytes = 16, algorithm = 'aes-256-ctr') {
16
+ const iv = buffer.slice(0, bytes)
17
17
  const decipher = crypto.createDecipheriv(algorithm, hashKey(key), iv)
18
- return Buffer.concat([decipher.update(buffer.slice(16)), decipher.final()])
18
+ return Buffer.concat([decipher.update(buffer.slice(bytes)), decipher.final()])
19
19
  }
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env node
2
+
3
+ import {
4
+ decrypt
5
+ } from '@sequencemedia/crypto'
6
+
7
+ const {
8
+ env: {
9
+ CRYPTO_KEY
10
+ } = {},
11
+ stdout,
12
+ openStdin
13
+ } = process
14
+
15
+ let collector = Buffer.from('')
16
+
17
+ openStdin()
18
+ .on('data', (buffer) => {
19
+ collector = Buffer.concat([collector, buffer])
20
+ })
21
+ .on('end', () => {
22
+ stdout.write(decrypt(collector, CRYPTO_KEY))
23
+ })
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env node
2
+
3
+ import {
4
+ encrypt
5
+ } from '@sequencemedia/crypto'
6
+
7
+ const {
8
+ env: {
9
+ CRYPTO_KEY
10
+ } = {},
11
+ stdout,
12
+ openStdin
13
+ } = process
14
+
15
+ let collector = Buffer.from('')
16
+
17
+ openStdin()
18
+ .on('data', (buffer) => {
19
+ collector = Buffer.concat([collector, buffer])
20
+ })
21
+ .on('end', () => {
22
+ stdout.write(encrypt(collector, CRYPTO_KEY))
23
+ })