@tinypudding/puddy-lib
Advanced tools
Comparing version 1.1.31 to 1.1.32
@@ -1,14 +0,30 @@ | ||
module.exports = function (tinyCrypto, text) { | ||
// Module | ||
const crypto = require('crypto'); | ||
const cryptoAction = function (tinyCrypto, key, text) { | ||
const crypto = require('crypto'); | ||
let textParts = text.split(':'); | ||
let iv = Buffer.from(textParts.shift(), tinyCrypto.stringType); | ||
let encryptedText = Buffer.from(textParts.join(':'), tinyCrypto.stringType); | ||
let decipher = crypto.createDecipheriv(tinyCrypto.algorithm, Buffer.from(tinyCrypto.key), iv); | ||
let decipher = crypto.createDecipheriv(tinyCrypto.algorithm, Buffer.from(key), iv); | ||
let decrypted = decipher.update(encryptedText); | ||
decrypted = Buffer.concat([decrypted, decipher.final()]); | ||
return decrypted.toString(); | ||
} | ||
// Export | ||
module.exports = function (tinyCrypto, text) { | ||
// Prepare Result | ||
let result = text; | ||
if (!Array.isArray(tinyCrypto.key)) { tinyCrypto.key = [tinyCrypto.key]; } | ||
for (const item in tinyCrypto.key) { | ||
result = cryptoAction(tinyCrypto, tinyCrypto.key[item], result); | ||
} | ||
// Complete | ||
return result; | ||
}; |
@@ -1,6 +0,7 @@ | ||
module.exports = function (tinyCrypto, text) { | ||
// Module | ||
const crypto = require('crypto'); | ||
const cryptoAction = function (tinyCrypto, key, text) { | ||
const crypto = require('crypto'); | ||
let iv = crypto.randomBytes(tinyCrypto.IV_LENGTH); | ||
let cipher = crypto.createCipheriv(tinyCrypto.algorithm, Buffer.from(tinyCrypto.key), iv); | ||
let cipher = crypto.createCipheriv(tinyCrypto.algorithm, Buffer.from(key), iv); | ||
let encrypted = cipher.update(text); | ||
@@ -10,2 +11,17 @@ encrypted = Buffer.concat([encrypted, cipher.final()]); | ||
}; | ||
// Export | ||
module.exports = function (tinyCrypto, text) { | ||
// Prepare Result | ||
let result = text; | ||
if (!Array.isArray(tinyCrypto.key)) { tinyCrypto.key = [tinyCrypto.key]; } | ||
for (const item in tinyCrypto.key) { | ||
result = cryptoAction(tinyCrypto, tinyCrypto.key[item], result); | ||
} | ||
// Complete | ||
return result; | ||
}; |
{ | ||
"name": "@tinypudding/puddy-lib", | ||
"version": "1.1.31", | ||
"version": "1.1.32", | ||
"description": "Essential codes to run the other repositories from the Tiny Pudding Account.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
74418
1193