UNPKG

outers

Version:

outers - a all in one package for your day to day use

73 lines (70 loc) 3.4 kB
"use strict"; /* eslint-disable @typescript-eslint/no-explicit-any */ 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.EncryptSync = exports.Encrypt = void 0; // Encrypt and Decrypt Imports const crypto_js_1 = __importDefault(require("crypto-js")); /** * The function reActEncrypt takes a string of data and encrypts it using the AES algorithm with a * specified key. * @param {str} Data - The `Data` parameter is the string that you want to encrypt. It is the data that * you want to keep secure and confidential. * @param [Key=YourKey] - The "Key" parameter is an optional parameter that represents the encryption * key used to encrypt the data. If no key is provided, the default value is set to 'YourKey'. * @returns the encrypted data as a string. */ /** Encrypt function encrypts a string of data using the provided key. // It uses the CryptoJS library to perform the AES encryption. // // @param {string} data - The `data` parameter is the string that you want to encrypt. It is the data that // you want to keep secure and confidential. // // @param {string} [Key] - The `key` parameter is an optional parameter that represents the encryption // key used to encrypt the data. If no key is provided. // // @returns the encrypted data as a string. */ function Encrypt(data, Key) { return __awaiter(this, void 0, void 0, function* () { if (!Key) { throw new Error("Missing key"); } // Encrypt data using CryptoJS const encryptedData = crypto_js_1.default.AES.encrypt(data, Key).toString(); return encryptedData; }); } exports.Encrypt = Encrypt; /** EncryptSync function encrypts a string of data using the provided key. It uses the CryptoJS library to perform the AES encryption. This function operates synchronously, which can impact performance in some scenarios. @param {string} Data - The `data` parameter is the string that you want to encrypt. It is the data that you want to keep secure and confidential. @param {string} [Key] - The `key` parameter is an optional parameter that represents the encryption key used to encrypt the data. If no key is provided, the default value is set to 'YourKey'. *@returns the encrypted data as a string. */ function EncryptSync(Data, Key) { if (!Key) { throw new Error("Missing key"); } // Encrypt data const encryptedData = crypto_js_1.default.AES.encrypt(Data, Key).toString(); // Encrypt data return encryptedData; // Return encrypted data } exports.EncryptSync = EncryptSync; //# sourceMappingURL=Encrypt.js.map