namirasoft-core
Advanced tools
Comparing version 1.2.13 to 1.2.14
@@ -30,11 +30,19 @@ "use strict"; | ||
static encrypt(algorithm, secret, message) { | ||
const iv = Buffer.alloc(16, 0); | ||
const iv = crypto.randomBytes(16); | ||
const cipher = crypto.createCipheriv(algorithm, secret, iv); | ||
return cipher.update(JSON.stringify(message), 'utf8', 'hex') + cipher.final('hex'); | ||
const encrypted = Buffer.concat([cipher.update(JSON.stringify(message), 'utf8'), cipher.final()]); | ||
const authTag = cipher.getAuthTag(); | ||
const ivHex = iv.toString('hex'); | ||
const authTagHex = authTag.toString('hex'); | ||
const encryptedHex = encrypted.toString('hex'); | ||
return [ivHex, authTagHex, encryptedHex].join(";"); | ||
} | ||
static decrypt(algorithm, secret, message) { | ||
let encryptedText = Buffer.from(message, 'hex'); | ||
const iv = Buffer.alloc(16, 0); | ||
const [ivHex, authTagHex, encryptedHex] = message.split(';'); | ||
const iv = Buffer.from(ivHex, 'hex'); | ||
const authTag = Buffer.from(authTagHex, 'hex'); | ||
const encrypte = Buffer.from(encryptedHex, 'hex'); | ||
const decipher = crypto.createDecipheriv(algorithm, secret, iv); | ||
let decrypted = decipher.update(encryptedText); | ||
decipher.setAuthTag(authTag); | ||
let decrypted = decipher.update(encrypte); | ||
decrypted = Buffer.concat([decrypted, decipher.final()]); | ||
@@ -41,0 +49,0 @@ return JSON.parse(decrypted.toString()); |
{ | ||
"name": "namirasoft-core", | ||
"description": "Namira Software Corporation Core NPM Package", | ||
"version": "1.2.13", | ||
"version": "1.2.14", | ||
"main": "./dist/index.js", | ||
@@ -11,3 +11,3 @@ "types": "./dist/index.d.ts", | ||
"dependencies": { | ||
"@types/node": "^20.11.24", | ||
"@types/node": "^20.11.25", | ||
"axios": "^1.6.7", | ||
@@ -14,0 +14,0 @@ "moment": "^2.30.1", |
@@ -0,0 +0,0 @@ export type BaseDatabaseRow<ID> = |
@@ -0,0 +0,0 @@ import axios, { AxiosRequestConfig, AxiosResponse } from "axios"; |
@@ -0,0 +0,0 @@ import { ErrorOperation } from "./ErrorOperation"; |
@@ -0,0 +0,0 @@ import { Country } from "./Country"; |
@@ -0,0 +0,0 @@ export class Country |
@@ -0,0 +0,0 @@ import { Country } from "./Country"; |
@@ -7,14 +7,22 @@ import * as crypto from 'node:crypto'; | ||
{ | ||
const iv = Buffer.alloc(16, 0); | ||
const iv = crypto.randomBytes(16); | ||
const cipher = crypto.createCipheriv(algorithm, secret, iv); | ||
return cipher.update(JSON.stringify(message), 'utf8', 'hex') + cipher.final('hex'); | ||
const encrypted = Buffer.concat([cipher.update(JSON.stringify(message), 'utf8'), cipher.final()]); | ||
const authTag = (cipher as any).getAuthTag(); | ||
const ivHex = iv.toString('hex'); | ||
const authTagHex = authTag.toString('hex'); | ||
const encryptedHex = encrypted.toString('hex'); | ||
return [ivHex, authTagHex, encryptedHex].join(";"); | ||
} | ||
private static decrypt<T>(algorithm: string, secret: string, message: string): T | ||
{ | ||
let encryptedText = Buffer.from(message, 'hex'); | ||
const [ivHex, authTagHex, encryptedHex] = message.split(';'); | ||
const iv = Buffer.from(ivHex, 'hex'); | ||
const authTag = Buffer.from(authTagHex, 'hex'); | ||
const encrypte = Buffer.from(encryptedHex, 'hex'); | ||
const iv = Buffer.alloc(16, 0); | ||
const decipher = crypto.createDecipheriv(algorithm, secret, iv); | ||
(decipher as any).setAuthTag(authTag); | ||
let decrypted = decipher.update(encryptedText); | ||
let decrypted = decipher.update(encrypte); | ||
decrypted = Buffer.concat([decrypted, decipher.final()]); | ||
@@ -21,0 +29,0 @@ return JSON.parse(decrypted.toString()); |
@@ -0,0 +0,0 @@ import { HTTPError } from "./HTTPError"; |
@@ -0,0 +0,0 @@ let fs: any; |
@@ -0,0 +0,0 @@ export class GeoOperation |
@@ -0,0 +0,0 @@ import * as crypto from 'node:crypto'; |
@@ -0,0 +0,0 @@ export class HTTPError extends Error |
@@ -0,0 +0,0 @@ export enum HTTPMethod |
@@ -0,0 +0,0 @@ export * from "./BaseDatabaseRow"; |
@@ -0,0 +0,0 @@ export abstract class IStorage |
@@ -0,0 +0,0 @@ import { IStorage } from "./IStorage.js"; |
@@ -0,0 +0,0 @@ import { IStorage } from "./IStorage"; |
@@ -0,0 +0,0 @@ import { ConvertService } from "./ConvertService"; |
@@ -0,0 +0,0 @@ let fs: any; |
@@ -0,0 +0,0 @@ import * as Phone from 'phone'; |
@@ -0,0 +0,0 @@ export class StringOperation |
@@ -0,0 +0,0 @@ import moment from "moment"; |
@@ -0,0 +0,0 @@ import { ParsedNameValue } from "./ParsedNameValue"; |
@@ -0,0 +0,0 @@ export class VersionOperation |
@@ -0,0 +0,0 @@ { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
238776
106
3521
Updated@types/node@^20.11.25