outers
Version:
outers - a all in one package for your day to day use
60 lines • 2.97 kB
JavaScript
;
/* 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.DecryptSync = exports.Decrypt = void 0;
// Encrypt and Decrypt Imports
const crypto_js_1 = __importDefault(require("crypto-js"));
/**
* The `nodeDecrypt` function takes in an encrypted data string and a key, decrypts the data using
* AES-CBC encryption, and returns the decrypted data as a UTF-8 string.
* @param {str} Data - The `Data` parameter is a string that represents the encrypted data that you
* want to decrypt.
* @param [Key=YourKey] - The `Key` parameter is the encryption key used to decrypt the data. It is a
* string value that represents the secret key used in the AES-CBC encryption algorithm. By default,
* the value is set to 'YourKey', but you can provide your own key as an argument when calling the `
* @returns the decrypted data as a UTF-8 string.
*/
function Decrypt(Data, Key) {
return __awaiter(this, void 0, void 0, function* () {
if (!Key) {
throw new Error("Missing key");
}
// Decrypt data
const bytes = crypto_js_1.default.AES.decrypt(Data, Key);
const decryptedText = bytes.toString(crypto_js_1.default.enc.Utf8);
// Return decrypted data
return decryptedText !== null && decryptedText !== void 0 ? decryptedText : ""; // Return decrypted data
});
}
exports.Decrypt = Decrypt;
/**
* Decrypts the given data using the specified key.
* @param {string} Data - The data to be decrypted.
* @param {string} Key - The key used for decryption.
* @returns {string} - The decrypted data.
* @throws {Error} - If the key is missing.
*/
function DecryptSync(Data, Key) {
if (!Key) {
throw new Error("Missing key");
}
// Decrypt data
const bytes = crypto_js_1.default.AES.decrypt(Data, Key);
const decryptedText = bytes.toString(crypto_js_1.default.enc.Utf8);
// Return decrypted data
return decryptedText !== null && decryptedText !== void 0 ? decryptedText : ""; // Return decrypted data
}
exports.DecryptSync = DecryptSync;
//# sourceMappingURL=Decrypt.js.map