Updates
This commit is contained in:
+2
-1
@@ -2,9 +2,10 @@ type Param = {
|
||||
encryptedString: string;
|
||||
encryptionKey?: string;
|
||||
encryptionSalt?: string;
|
||||
debug?: boolean;
|
||||
};
|
||||
/**
|
||||
* # Decrypt Function
|
||||
*/
|
||||
export default function decrypt({ encryptedString, encryptionKey, encryptionSalt, }: Param): string;
|
||||
export default function decrypt({ encryptedString, encryptionKey, encryptionSalt, debug, }: Param): string;
|
||||
export {};
|
||||
|
||||
+10
-8
@@ -11,19 +11,21 @@ const grab_keys_1 = __importDefault(require("../../utils/grab-keys"));
|
||||
/**
|
||||
* # Decrypt Function
|
||||
*/
|
||||
function decrypt({ encryptedString, encryptionKey, encryptionSalt, }) {
|
||||
var _a;
|
||||
function decrypt({ encryptedString, encryptionKey, encryptionSalt, debug, }) {
|
||||
if (!(encryptedString === null || encryptedString === void 0 ? void 0 : encryptedString.match(/./))) {
|
||||
console.log("Encrypted string is invalid");
|
||||
if (debug)
|
||||
console.log("Encrypted string is invalid");
|
||||
return encryptedString;
|
||||
}
|
||||
const { key: encrptKey, salt, keyLen, algorithm, bufferAllocSize, } = (0, grab_keys_1.default)({ encryptionKey });
|
||||
if (!(encrptKey === null || encrptKey === void 0 ? void 0 : encrptKey.match(/.{8,}/))) {
|
||||
console.log("Decrption key is invalid");
|
||||
if (debug)
|
||||
console.log("Decrption key is invalid");
|
||||
return encryptedString;
|
||||
}
|
||||
if (!(salt === null || salt === void 0 ? void 0 : salt.match(/.{8,}/))) {
|
||||
console.log("Decrption salt is invalid");
|
||||
if (debug)
|
||||
console.log("Decrption salt is invalid");
|
||||
return encryptedString;
|
||||
}
|
||||
let key = (0, crypto_1.scryptSync)(encrptKey, salt, keyLen);
|
||||
@@ -35,9 +37,9 @@ function decrypt({ encryptedString, encryptionKey, encryptionSalt, }) {
|
||||
return decrypted;
|
||||
}
|
||||
catch (error) {
|
||||
console.log("Error in decrypting =>", error.message);
|
||||
console.log("encryptedString =>", encryptedString);
|
||||
(_a = global.ERROR_CALLBACK) === null || _a === void 0 ? void 0 : _a.call(global, `Error Decrypting data`, error);
|
||||
if (debug) {
|
||||
console.log("Error Decrypting data", error);
|
||||
}
|
||||
return encryptedString;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@ const grab_keys_1 = __importDefault(require("../../utils/grab-keys"));
|
||||
* # Encrypt String
|
||||
*/
|
||||
function encrypt({ data, encryptionKey, encryptionSalt, }) {
|
||||
var _a;
|
||||
if (!(data === null || data === void 0 ? void 0 : data.match(/./))) {
|
||||
console.log("Encryption string is invalid");
|
||||
return data;
|
||||
@@ -37,7 +36,6 @@ function encrypt({ data, encryptionKey, encryptionSalt, }) {
|
||||
}
|
||||
catch (error) {
|
||||
console.log("Error in encrypting =>", error.message);
|
||||
(_a = global.ERROR_CALLBACK) === null || _a === void 0 ? void 0 : _a.call(global, `Error Encrypting Data`, error);
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user