@gerync/utils 1.1.0 → 1.2.0
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.
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Encrypt.d.ts","sourceRoot":"","sources":["../../functions/Encrypt.ts"],"names":[],"mappings":"AAEA,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAM7D;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAQ7D"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import crypto from 'crypto';
|
|
2
|
+
export function encryptData(data, key) {
|
|
3
|
+
const iv = crypto.randomBytes(16);
|
|
4
|
+
const cipher = crypto.createCipheriv('aes-256-cbc', Buffer.from(key, 'utf-8'), iv);
|
|
5
|
+
let encrypted = cipher.update(data, 'utf8', 'hex');
|
|
6
|
+
encrypted += cipher.final('hex');
|
|
7
|
+
return iv.toString('hex') + ':' + encrypted;
|
|
8
|
+
}
|
|
9
|
+
export function decryptData(data, key) {
|
|
10
|
+
const textParts = data.split(':');
|
|
11
|
+
const iv = Buffer.from(textParts.shift() || '', 'hex');
|
|
12
|
+
const encryptedText = textParts.join(':');
|
|
13
|
+
const decipher = crypto.createDecipheriv('aes-256-cbc', Buffer.from(key, 'utf-8'), iv);
|
|
14
|
+
let decrypted = decipher.update(encryptedText, 'hex', 'utf8');
|
|
15
|
+
decrypted += decipher.final('utf8');
|
|
16
|
+
return decrypted;
|
|
17
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gerync/utils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "A collection of utilities for any type of project, providing logging, error handling, configuration management, and object manipulation helpers.",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|