@vivlab/api-database
Advanced tools
Comparing version 1.0.39 to 1.0.40
@@ -10,3 +10,2 @@ "use strict"; | ||
const KEYLEN = 64; | ||
const CIPHER_ALGORITHM = "aes-256-ctr"; | ||
const randomBytes = util_1.default.promisify(crypto_1.default.randomBytes); | ||
@@ -53,10 +52,2 @@ const scrypt = util_1.default.promisify(crypto_1.default.scrypt); | ||
exports.generateKeyPair = generateKeyPair; | ||
if (!process.env.CRYPTO_IV) | ||
throw new Error("Missing Crypto IV"); | ||
const CIPHER_IV = Buffer.from(process.env.CRYPTO_IV, "hex"); | ||
const CIPHER_KEY = crypto_1.default | ||
.createHash("sha256") | ||
.update(String(process.env.CRYPTO_KEY)) | ||
.digest("base64") | ||
.substr(0, 32); | ||
function cipher(data) { | ||
@@ -66,2 +57,3 @@ if (data == null) | ||
try { | ||
const { CIPHER_ALGORITHM, CIPHER_KEY, CIPHER_IV } = initCypher(); | ||
const cryptoCipher = crypto_1.default.createCipheriv(CIPHER_ALGORITHM, CIPHER_KEY, CIPHER_IV); | ||
@@ -81,2 +73,3 @@ let encrypted = cryptoCipher.update(data, "utf8", "hex"); | ||
try { | ||
const { CIPHER_ALGORITHM, CIPHER_KEY, CIPHER_IV } = initCypher(); | ||
const cryptoDecipher = crypto_1.default.createDecipheriv(CIPHER_ALGORITHM, CIPHER_KEY, CIPHER_IV); | ||
@@ -92,2 +85,14 @@ let decrypted = cryptoDecipher.update(data, "hex", "utf8"); | ||
exports.decipher = decipher; | ||
function initCypher() { | ||
if (!process.env.CRYPTO_IV) | ||
throw new Error("Missing Crypto IV"); | ||
const CIPHER_ALGORITHM = "aes-256-ctr"; | ||
const CIPHER_IV = Buffer.from(process.env.CRYPTO_IV, "hex"); | ||
const CIPHER_KEY = crypto_1.default | ||
.createHash("sha256") | ||
.update(String(process.env.CRYPTO_KEY)) | ||
.digest("base64") | ||
.substr(0, 32); | ||
return { CIPHER_ALGORITHM, CIPHER_KEY, CIPHER_IV }; | ||
} | ||
//# sourceMappingURL=crypto.js.map |
{ | ||
"name": "@vivlab/api-database", | ||
"version": "1.0.39", | ||
"version": "1.0.40", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
Sorry, the diff of this file is not supported yet
378450
6154