@sparted/shared-library 1.7.0 → 1.7.1
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 +12 -0
- package/crypto/aes256.js +20 -8
- package/crypto/aes256.js.map +1 -1
- package/package.json +1 -1
package/crypto/aes256.d.ts
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
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
|
+
*/
|
|
1
7
|
declare function encrypt(data: string, key: string, iv: string): string;
|
|
8
|
+
/**
|
|
9
|
+
* Decrypt 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
|
+
*/
|
|
2
14
|
declare function decrypt(data: string, key: string, iv: string): string;
|
|
3
15
|
export { encrypt, decrypt };
|
package/crypto/aes256.js
CHANGED
|
@@ -5,27 +5,39 @@ 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
|
+
*/
|
|
8
14
|
function encrypt(data, key, iv) {
|
|
9
|
-
if (key.length !==
|
|
15
|
+
if (key.length !== 64)
|
|
10
16
|
throw new Error('Key must be 256 bits long');
|
|
11
|
-
if (iv.length !==
|
|
17
|
+
if (iv.length !== 32)
|
|
12
18
|
throw new Error('IV must be 128 bits long');
|
|
13
|
-
const cipher = aes.encrypt(data, cryptoJs.enc.
|
|
19
|
+
const cipher = aes.encrypt(data, cryptoJs.enc.Hex.parse(key), {
|
|
14
20
|
mode: cryptoJs.mode.CBC,
|
|
15
21
|
padding: cryptoJs.pad.Pkcs7,
|
|
16
|
-
iv: cryptoJs.enc.
|
|
22
|
+
iv: cryptoJs.enc.Hex.parse(iv),
|
|
17
23
|
});
|
|
18
24
|
return cryptoJs.enc.Base64.stringify(cipher.ciphertext);
|
|
19
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* Decrypt data using AES-256-CBC
|
|
28
|
+
* @param data
|
|
29
|
+
* @param key Must be a 256 bits hex string
|
|
30
|
+
* @param iv Must be a 128 bits hex string
|
|
31
|
+
*/
|
|
20
32
|
function decrypt(data, key, iv) {
|
|
21
|
-
if (key.length !==
|
|
33
|
+
if (key.length !== 64)
|
|
22
34
|
throw new Error('Key must be 256 bits long');
|
|
23
|
-
if (iv.length !==
|
|
35
|
+
if (iv.length !== 32)
|
|
24
36
|
throw new Error('IV must be 128 bits long');
|
|
25
|
-
const cipher = aes.decrypt(data, cryptoJs.enc.
|
|
37
|
+
const cipher = aes.decrypt(data, cryptoJs.enc.Hex.parse(key), {
|
|
26
38
|
mode: cryptoJs.mode.CBC,
|
|
27
39
|
padding: cryptoJs.pad.Pkcs7,
|
|
28
|
-
iv: cryptoJs.enc.
|
|
40
|
+
iv: cryptoJs.enc.Hex.parse(iv),
|
|
29
41
|
});
|
|
30
42
|
return cryptoJs.enc.Utf8.stringify(cipher);
|
|
31
43
|
}
|
package/crypto/aes256.js.map
CHANGED
|
@@ -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 !==
|
|
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\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 */\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.Base64.stringify(cipher.ciphertext);\n}\n\n/**\n * Decrypt 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 */\nfunction decrypt(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 = cryptoDecript(data, enc.Hex.parse(key), {\n mode: mode.CBC,\n padding: pad.Pkcs7,\n iv: enc.Hex.parse(iv),\n });\n return enc.Utf8.stringify(cipher);\n}\n\nexport { encrypt, decrypt };\n"],"names":["cryptoEncrypt","enc","mode","pad","cryptoDecript"],"mappings":";;;;;;;AAGA;;;;;AAKG;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,GAA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