@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.
- package/crypto/aes256.d.ts +8 -2
- package/crypto/aes256.js +12 -18
- package/crypto/aes256.js.map +1 -1
- package/crypto/index.d.ts +1 -1
- package/crypto/index.js +0 -1
- package/crypto/index.js.map +1 -1
- package/index.js +0 -1
- package/index.js.map +1 -1
- package/package.json +1 -1
package/crypto/aes256.d.ts
CHANGED
|
@@ -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
|
-
|
|
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 !==
|
|
16
|
+
if (key.length !== 64)
|
|
10
17
|
throw new Error('Key must be 256 bits long');
|
|
11
|
-
if (iv.length !==
|
|
18
|
+
if (iv.length !== 32)
|
|
12
19
|
throw new Error('IV must be 128 bits long');
|
|
13
|
-
const cipher = aes.encrypt(data, cryptoJs.enc.
|
|
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.
|
|
23
|
+
iv: cryptoJs.enc.Hex.parse(iv),
|
|
17
24
|
});
|
|
18
|
-
return cryptoJs.enc.
|
|
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
|
package/crypto/aes256.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aes256.js","sources":["../../src/crypto/aes256.ts"],"sourcesContent":["import { encrypt as cryptoEncrypt
|
|
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
|
|
1
|
+
export { encrypt } from './aes256';
|
package/crypto/index.js
CHANGED
package/crypto/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/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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|