axiodb
Version:
A blazing-fast, lightweight, and scalable nodejs package based DBMS for modern application. Supports schemas, encryption, and advanced query capabilities.
94 lines • 3.89 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.CryptoHelper = void 0;
/* eslint-disable @typescript-eslint/no-explicit-any */
// All Imports
const node_os_1 = require("node:os");
const response_helper_1 = __importDefault(require("./response.helper"));
const outers_1 = require("outers");
const Converter_helper_1 = __importDefault(require("./Converter.helper"));
/**
* Helper class for cryptographic operations such as encryption and decryption.
*/
class CryptoHelper {
/**
* Constructor to initialize the CryptoHelper class.
* @param encryptionKey - Optional encryption key. If not provided, a default key based on hostname and platform will be used.
*/
constructor(encryptionKey) {
/**
* Instance of ResponseHelper to handle responses.
*/
this.responseHelper = new response_helper_1.default();
/**
* Instance of Converter class for converting data formats.
*/
this.Converter = new Converter_helper_1.default();
this.encryptionKey = encryptionKey || `${(0, node_os_1.hostname)()}-${(0, node_os_1.platform)()}`;
this.responseHelper = new response_helper_1.default();
this.Cryptography = new outers_1.ClassBased.CryptoGraphy(this.encryptionKey);
this.Converter = new Converter_helper_1.default();
}
// methods
/**
* Sets a new encryption key.
* @param encryptionKey - The new encryption key to be set.
* @returns A promise that resolves to a success response.
*/
setEncryptionKey(encryptionKey) {
return __awaiter(this, void 0, void 0, function* () {
this.encryptionKey = encryptionKey;
return this.responseHelper.Success("Encryption key has been set successfully");
});
}
/**
* Encrypts data asynchronously.
* @param data - The data to be encrypted.
* @returns A promise that resolves to the encrypted data as a string.
*/
encrypt(data) {
return __awaiter(this, void 0, void 0, function* () {
return yield this.Cryptography.Encrypt(data);
});
}
/**
* Decrypts data asynchronously.
* @param data - The data to be decrypted.
* @returns A promise that resolves to the decrypted data as an object.
*/
decrypt(data) {
return __awaiter(this, void 0, void 0, function* () {
return this.Converter.ToObject(yield this.Cryptography.Decrypt(data));
});
}
/**
* Encrypts data synchronously.
* @param data - The data to be encrypted.
* @returns The encrypted data as a string.
*/
encryptSync(data) {
return this.Cryptography.EncryptSync(data);
}
/**
* Decrypts data synchronously.
* @param data - The data to be decrypted.
* @returns The decrypted data as an object.
*/
decryptSync(data) {
return this.Converter.ToObject(this.Cryptography.DecryptSync(data));
}
}
exports.CryptoHelper = CryptoHelper;
//# sourceMappingURL=Crypto.helper.js.map