npm-pkg-hook 1.3.2 → 1.3.3
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/package.json
CHANGED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import crypto from 'crypto'
|
|
2
|
+
|
|
3
|
+
function generateEncryptionKey(password, salt) {
|
|
4
|
+
return crypto
|
|
5
|
+
.pbkdf2Sync(password, salt, 100000, 32, 'sha256')
|
|
6
|
+
.toString('hex')
|
|
7
|
+
.slice(0, 32)
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const ENCRYPTION_KEY = generateEncryptionKey(
|
|
11
|
+
'tu-contraseña',
|
|
12
|
+
'alguna-sal-segura'
|
|
13
|
+
)
|
|
14
|
+
const IV_LENGTH = 16 // Para AES, este siempre debe ser 16
|
|
15
|
+
|
|
16
|
+
export const encryptSession = (text) => {
|
|
17
|
+
const iv = crypto.randomBytes(IV_LENGTH)
|
|
18
|
+
const cipher = crypto.createCipheriv(
|
|
19
|
+
'aes-256-cbc',
|
|
20
|
+
Buffer.from(ENCRYPTION_KEY),
|
|
21
|
+
iv
|
|
22
|
+
)
|
|
23
|
+
let encrypted = cipher.update(text)
|
|
24
|
+
encrypted = Buffer.concat([encrypted, cipher.final()])
|
|
25
|
+
return iv.toString('hex') + ':' + encrypted.toString('hex')
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const decryptSession = (text) => {
|
|
29
|
+
const textParts = text.split(':')
|
|
30
|
+
const iv = Buffer.from(textParts.shift(), 'hex')
|
|
31
|
+
const encryptedText = Buffer.from(textParts.join(':'), 'hex')
|
|
32
|
+
const decipher = crypto.createDecipheriv(
|
|
33
|
+
'aes-256-cbc',
|
|
34
|
+
Buffer.from(ENCRYPTION_KEY),
|
|
35
|
+
iv
|
|
36
|
+
)
|
|
37
|
+
let decrypted = decipher.update(encryptedText)
|
|
38
|
+
decrypted = Buffer.concat([decrypted, decipher.final()])
|
|
39
|
+
return decrypted.toString()
|
|
40
|
+
}
|
package/src/hooks/index.js
CHANGED