@sparted/shared-library 1.7.0 → 1.7.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.
@@ -1,3 +1,9 @@
1
+ /**
2
+ * Encrypt data using AES-256-CBC
3
+ * @param data
4
+ * @param key Must be a 256 bits hex string
5
+ * @param iv Must be a 128 bits hex string
6
+ * @returns Encrypted data as a hex string
7
+ */
1
8
  declare function encrypt(data: string, key: string, iv: string): string;
2
- declare function decrypt(data: string, key: string, iv: string): string;
3
- export { encrypt, decrypt };
9
+ export { encrypt };
package/crypto/aes256.js CHANGED
@@ -5,31 +5,25 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var aes = require('crypto-js/aes');
6
6
  var cryptoJs = require('crypto-js');
7
7
 
8
+ /**
9
+ * Encrypt data using AES-256-CBC
10
+ * @param data
11
+ * @param key Must be a 256 bits hex string
12
+ * @param iv Must be a 128 bits hex string
13
+ * @returns Encrypted data as a hex string
14
+ */
8
15
  function encrypt(data, key, iv) {
9
- if (key.length !== 32)
16
+ if (key.length !== 64)
10
17
  throw new Error('Key must be 256 bits long');
11
- if (iv.length !== 16)
18
+ if (iv.length !== 32)
12
19
  throw new Error('IV must be 128 bits long');
13
- const cipher = aes.encrypt(data, cryptoJs.enc.Utf8.parse(key), {
20
+ const cipher = aes.encrypt(data, cryptoJs.enc.Hex.parse(key), {
14
21
  mode: cryptoJs.mode.CBC,
15
22
  padding: cryptoJs.pad.Pkcs7,
16
- iv: cryptoJs.enc.Utf8.parse(iv),
23
+ iv: cryptoJs.enc.Hex.parse(iv),
17
24
  });
18
- return cryptoJs.enc.Base64.stringify(cipher.ciphertext);
19
- }
20
- function decrypt(data, key, iv) {
21
- if (key.length !== 32)
22
- throw new Error('Key must be 256 bits long');
23
- if (iv.length !== 16)
24
- throw new Error('IV must be 128 bits long');
25
- const cipher = aes.decrypt(data, cryptoJs.enc.Utf8.parse(key), {
26
- mode: cryptoJs.mode.CBC,
27
- padding: cryptoJs.pad.Pkcs7,
28
- iv: cryptoJs.enc.Utf8.parse(iv),
29
- });
30
- return cryptoJs.enc.Utf8.stringify(cipher);
25
+ return cryptoJs.enc.Hex.stringify(cipher.ciphertext);
31
26
  }
32
27
 
33
- exports.decrypt = decrypt;
34
28
  exports.encrypt = encrypt;
35
29
  //# sourceMappingURL=aes256.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"aes256.js","sources":["../../src/crypto/aes256.ts"],"sourcesContent":["import { encrypt as cryptoEncrypt, decrypt as cryptoDecript } from 'crypto-js/aes';\nimport { enc, mode, pad } from 'crypto-js';\n\nfunction encrypt(data: string, key: string, iv: string): string {\n if (key.length !== 32) throw new Error('Key must be 256 bits long');\n if (iv.length !== 16) throw new Error('IV must be 128 bits long');\n const cipher = cryptoEncrypt(data, enc.Utf8.parse(key), {\n mode: mode.CBC,\n padding: pad.Pkcs7,\n iv: enc.Utf8.parse(iv),\n });\n return enc.Base64.stringify(cipher.ciphertext);\n}\n\nfunction decrypt(data: string, key: string, iv: string): string {\n if (key.length !== 32) throw new Error('Key must be 256 bits long');\n if (iv.length !== 16) throw new Error('IV must be 128 bits long');\n const cipher = cryptoDecript(data, enc.Utf8.parse(key), {\n mode: mode.CBC,\n padding: pad.Pkcs7,\n iv: enc.Utf8.parse(iv),\n });\n return enc.Utf8.stringify(cipher);\n}\n\nexport { encrypt, decrypt };\n"],"names":["cryptoEncrypt","enc","mode","pad","cryptoDecript"],"mappings":";;;;;;;AAGA,SAAS,OAAO,CAAC,IAAY,EAAE,GAAW,EAAE,EAAU,EAAA;AACpD,IAAA,IAAI,GAAG,CAAC,MAAM,KAAK,EAAE;AAAE,QAAA,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;AACpE,IAAA,IAAI,EAAE,CAAC,MAAM,KAAK,EAAE;AAAE,QAAA,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC;AAClE,IAAA,MAAM,MAAM,GAAGA,WAAa,CAAC,IAAI,EAAEC,YAAG,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE;QACtD,IAAI,EAAEC,aAAI,CAAC,GAAG;QACd,OAAO,EAAEC,YAAG,CAAC,KAAK;QAClB,EAAE,EAAEF,YAAG,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;AACvB,KAAA,CAAC,CAAC;IACH,OAAOA,YAAG,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;AACjD,CAAC;AAED,SAAS,OAAO,CAAC,IAAY,EAAE,GAAW,EAAE,EAAU,EAAA;AACpD,IAAA,IAAI,GAAG,CAAC,MAAM,KAAK,EAAE;AAAE,QAAA,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;AACpE,IAAA,IAAI,EAAE,CAAC,MAAM,KAAK,EAAE;AAAE,QAAA,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC;AAClE,IAAA,MAAM,MAAM,GAAGG,WAAa,CAAC,IAAI,EAAEH,YAAG,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE;QACtD,IAAI,EAAEC,aAAI,CAAC,GAAG;QACd,OAAO,EAAEC,YAAG,CAAC,KAAK;QAClB,EAAE,EAAEF,YAAG,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;AACvB,KAAA,CAAC,CAAC;IACH,OAAOA,YAAG,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;AACpC;;;;;"}
1
+ {"version":3,"file":"aes256.js","sources":["../../src/crypto/aes256.ts"],"sourcesContent":["import { encrypt as cryptoEncrypt } from 'crypto-js/aes';\nimport { enc, mode, pad } from 'crypto-js';\n\n/**\n * Encrypt data using AES-256-CBC\n * @param data\n * @param key Must be a 256 bits hex string\n * @param iv Must be a 128 bits hex string\n * @returns Encrypted data as a hex string\n */\nfunction encrypt(data: string, key: string, iv: string): string {\n if (key.length !== 64) throw new Error('Key must be 256 bits long');\n if (iv.length !== 32) throw new Error('IV must be 128 bits long');\n const cipher = cryptoEncrypt(data, enc.Hex.parse(key), {\n mode: mode.CBC,\n padding: pad.Pkcs7,\n iv: enc.Hex.parse(iv),\n });\n return enc.Hex.stringify(cipher.ciphertext);\n}\n\nexport { encrypt };\n"],"names":["cryptoEncrypt","enc","mode","pad"],"mappings":";;;;;;;AAGA;;;;;;AAMG;AACH,SAAS,OAAO,CAAC,IAAY,EAAE,GAAW,EAAE,EAAU,EAAA;AACpD,IAAA,IAAI,GAAG,CAAC,MAAM,KAAK,EAAE;AAAE,QAAA,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;AACpE,IAAA,IAAI,EAAE,CAAC,MAAM,KAAK,EAAE;AAAE,QAAA,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC;AAClE,IAAA,MAAM,MAAM,GAAGA,WAAa,CAAC,IAAI,EAAEC,YAAG,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE;QACrD,IAAI,EAAEC,aAAI,CAAC,GAAG;QACd,OAAO,EAAEC,YAAG,CAAC,KAAK;QAClB,EAAE,EAAEF,YAAG,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;AACtB,KAAA,CAAC,CAAC;IACH,OAAOA,YAAG,CAAC,GAAG,CAAC,SAAS,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;AAC9C;;;;"}
package/crypto/index.d.ts CHANGED
@@ -1 +1 @@
1
- export { encrypt, decrypt } from './aes256';
1
+ export { encrypt } from './aes256';
package/crypto/index.js CHANGED
@@ -6,6 +6,5 @@ var aes256 = require('./aes256.js');
6
6
 
7
7
 
8
8
 
9
- exports.decrypt = aes256.decrypt;
10
9
  exports.encrypt = aes256.encrypt;
11
10
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;"}
package/index.js CHANGED
@@ -85,6 +85,5 @@ exports.delay = delay.delay;
85
85
  exports.replaceInTemplate = replaceInTemplate.replaceInTemplate;
86
86
  exports.isStringLengthWithinRange = isStringLengthWithinRange.isStringLengthWithinRange;
87
87
  exports.getContrastColor = getContrastColor.getContrastColor;
88
- exports.decrypt = aes256.decrypt;
89
88
  exports.encrypt = aes256.encrypt;
90
89
  //# sourceMappingURL=index.js.map
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sparted/shared-library",
3
- "version": "1.7.0",
3
+ "version": "1.7.2",
4
4
  "repository": "git@github.com:Sparted/shared-library.git",
5
5
  "author": {
6
6
  "name": "Sparted",