New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

@stemuli/utils

Package Overview
Dependencies
Maintainers
3
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@stemuli/utils - npm Package Compare versions

Comparing version
1.0.0
to
1.0.1
+25
lib/types.d.ts
/**
* Used in encrypting a string
* @param text
* @param secretKey
*/
export declare const doEncrypt: (text: string, secretKey: string) => string;
/**
* Used to decipher an encrypted string
* @param cipher {string} the encrypted string
* @param secretKey {string} the key used in encrypting the string
*/
export declare const doDecrypt: (cipher: string, secretKey: string) => string;
/**
*
* @param string string string to be hashed
* @param algorithm string default is sha256. Others include md5 and sha1
*/
export declare const hash: (string: string, algorithm?: string) => string;
/**
*
* @param hash {string} the hashed data as string
* @param str {string} the string to be compared
* @param algorithm {string} Default is sha256, others include sha1, md5
*/
export declare const compareHash: (hash: string, str: string, algorithm?: string) => boolean;
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.compareHash = exports.hash = exports.doDecrypt = exports.doEncrypt = void 0;
var crypto = __importStar(require("crypto"));
var algorithm = 'aes-256-cbc';
/**
* Used in encrypting a string
* @param text
* @param secretKey
*/
var doEncrypt = function (text, secretKey) {
var iv = crypto.randomBytes(16);
iv = crypto.createHash('md5').update(iv).digest('hex').substr(0, 16);
var key = crypto.createHash('md5').update(secretKey).digest('hex');
var cipher = crypto.createCipheriv(algorithm, key, iv);
var encrypted = Buffer.concat([cipher.update(text), cipher.final()]);
return iv + "/" + encrypted.toString('hex');
};
exports.doEncrypt = doEncrypt;
/**
* Used to decipher an encrypted string
* @param cipher {string} the encrypted string
* @param secretKey {string} the key used in encrypting the string
*/
var doDecrypt = function (cipher, secretKey) {
var str = cipher.split('/');
var iv = str[0];
var key = crypto.createHash('md5').update(secretKey).digest('hex');
// @ts-ignore
// const decipher = crypto.createDecipheriv(algorithm, secretKey, Buffer.from(hash.iv, 'hex'));
var decipher = crypto.createDecipheriv(algorithm, key, iv);
// @ts-ignore
var decrpyted = Buffer.concat([decipher.update(Buffer.from(str[1], 'hex')), decipher.final()]);
return decrpyted.toString();
};
exports.doDecrypt = doDecrypt;
/**
*
* @param string string string to be hashed
* @param algorithm string default is sha256. Others include md5 and sha1
*/
var hash = function (string, algorithm) {
if (algorithm === void 0) { algorithm = 'sha256'; }
var salt = crypto.randomBytes(16);
salt = crypto.createHash('md5').update(salt).digest('hex').substr(0, 16);
return salt + "/" + crypto.createHash(algorithm).update(string + ":" + salt).digest('hex');
};
exports.hash = hash;
/**
*
* @param hash {string} the hashed data as string
* @param str {string} the string to be compared
* @param algorithm {string} Default is sha256, others include sha1, md5
*/
var compareHash = function (hash, str, algorithm) {
if (algorithm === void 0) { algorithm = 'sha256'; }
var parts = hash.split('/');
var salt = parts[0];
return crypto.createHash(algorithm).update(str + ":" + salt).digest('hex') === parts[1];
};
exports.compareHash = compareHash;
//# sourceMappingURL=types.js.map
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../lib/types.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,6CAAiC;AAEjC,IAAM,SAAS,GAAG,aAAa,CAAC;AAEhC;;;;GAIG;AACI,IAAM,SAAS,GAAG,UAAC,IAAY,EAAE,SAA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C,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,EAAE,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;IACjG,OAAO,SAAS,CAAC,QAAQ,EAAE,CAAC;AAChC,CAAC,CAAC;AAVW,QAAA,SAAS,aAUpB;AAEF;;;;GAIG;AACI,IAAM,IAAI,GAAG,UAAC,MAAc,EAAE,SAA4B;IAA5B,0BAAA,EAAA,oBAA4B;IAC7D,IAAI,IAAI,GAAQ,MAAM,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;IACvC,IAAI,GAAG,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IACzE,OAAU,IAAI,SAAI,MAAM,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,MAAM,CAAI,MAAM,SAAI,IAAM,CAAC,CAAC,MAAM,CAAC,KAAK,CAAG,CAAC;AAC/F,CAAC,CAAC;AAJW,QAAA,IAAI,QAIf;AAEF;;;;;GAKG;AACI,IAAM,WAAW,GAAG,UAAC,IAAY,EAAE,GAAW,EAAE,SAA4B;IAA5B,0BAAA,EAAA,oBAA4B;IAC/E,IAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC9B,IAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;IACtB,OAAO,MAAM,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,MAAM,CAAI,GAAG,SAAI,IAAM,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC;AAC5F,CAAC,CAAC;AAJW,QAAA,WAAW,eAItB"}
+2
-1

@@ -1,1 +0,2 @@

export * from './lib/encryption';
import { doCompareHash as compareHash, doDecrypt as decryptString, doEncrypt as encryptString, doHash as hashString } from "./lib/encryption";
export { compareHash, decryptString, encryptString, hashString };
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./lib/encryption"), exports);
exports.hashString = exports.encryptString = exports.decryptString = exports.compareHash = void 0;
var encryption_1 = require("./lib/encryption");
Object.defineProperty(exports, "compareHash", { enumerable: true, get: function () { return encryption_1.doCompareHash; } });
Object.defineProperty(exports, "decryptString", { enumerable: true, get: function () { return encryption_1.doDecrypt; } });
Object.defineProperty(exports, "encryptString", { enumerable: true, get: function () { return encryption_1.doEncrypt; } });
Object.defineProperty(exports, "hashString", { enumerable: true, get: function () { return encryption_1.doHash; } });
// const hash = doHash('femi');
// console.log(hash, doCompareHash(hash, 'femi'));
// console.log(doDecrypt(doEncrypt('femi', 'hello'), 'hello' ));
//# sourceMappingURL=index.js.map

@@ -1,1 +0,1 @@

{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mDAAmC"}
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;AAAA,+CAK0B;AAQtB,4FAZiB,0BAAW,OAYjB;AACX,8FAZa,sBAAa,OAYb;AACb,8FAZa,sBAAa,OAYb;AACb,2FAZU,mBAAU,OAYV;AAGd,+BAA+B;AAC/B,kDAAkD;AAClD,gEAAgE"}

@@ -1,2 +0,27 @@

export declare const encrypt: (text: string) => string;
export declare const decrypt: (hash: string) => string;
/// <reference types="node" />
/**
* Used in encrypting a string
* @param {string} text String to be encrypted
* @param {string} secretKey Secret key to be used
*/
export declare const doEncrypt: (text: string, secretKey: string) => string;
/**
* Used to decipher an encrypted string
* @param {string} cipher the encrypted string
* @param {string} secretKey The secret key used in encrypting the string
*/
export declare const doDecrypt: (cipher: string, secretKey: string) => string;
/**
* Used in hashing strings
* @param {string} text string to be hashed
* @param {string} algorithm default is sha256. Others include md5 and sha1
* @salt? {string|Buffer} [salt] optional salt
*/
export declare const doHash: (text: string, algorithm?: string, salt?: string | Buffer) => string;
/**
*
* @param {string} hash the hashed data as string
* @param {string} string the string to be compared
* @param {string} [algorithm] Default is sha256, others include sha1, md5
*/
export declare const doCompareHash: (hash: string, text: string, algorithm?: string) => boolean;

@@ -22,7 +22,11 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.decrypt = exports.encrypt = void 0;
exports.doCompareHash = exports.doHash = exports.doDecrypt = exports.doEncrypt = void 0;
var crypto = __importStar(require("crypto"));
var algorithm = 'aes-256-cbc';
var secretKey = process.env.SERVER_ENCRYPTION_KEY || 'appSecret';
var encrypt = function (text) {
/**
* Used in encrypting a string
* @param {string} text String to be encrypted
* @param {string} secretKey Secret key to be used
*/
var doEncrypt = function (text, secretKey) {
var iv = crypto.randomBytes(16);

@@ -35,5 +39,10 @@ iv = crypto.createHash('md5').update(iv).digest('hex').substr(0, 16);

};
exports.encrypt = encrypt;
var decrypt = function (hash) {
var str = hash.split('/');
exports.doEncrypt = doEncrypt;
/**
* Used to decipher an encrypted string
* @param {string} cipher the encrypted string
* @param {string} secretKey The secret key used in encrypting the string
*/
var doDecrypt = function (cipher, secretKey) {
var str = cipher.split('/');
var iv = str[0];

@@ -45,6 +54,36 @@ var key = crypto.createHash('md5').update(secretKey).digest('hex');

// @ts-ignore
var decrpyted = Buffer.concat([decipher.update(Buffer.from(str[1], 'hex')), decipher.final()]);
return decrpyted.toString();
var decrypted = Buffer.concat([decipher.update(Buffer.from(str[1], 'hex')), decipher.final()]);
return decrypted.toString();
};
exports.decrypt = decrypt;
exports.doDecrypt = doDecrypt;
/**
* Used in hashing strings
* @param {string} text string to be hashed
* @param {string} algorithm default is sha256. Others include md5 and sha1
* @salt? {string|Buffer} [salt] optional salt
*/
var doHash = function (text, algorithm, salt) {
if (algorithm === void 0) { algorithm = 'sha256'; }
if (!salt) {
salt = crypto.randomBytes(16);
salt = salt.toString('hex');
}
var h = salt + "/" + crypto.createHash(algorithm).update(text + ":" + salt).digest('hex');
console.log(h);
return h;
};
exports.doHash = doHash;
/**
*
* @param {string} hash the hashed data as string
* @param {string} string the string to be compared
* @param {string} [algorithm] Default is sha256, others include sha1, md5
*/
var doCompareHash = function (hash, text, algorithm) {
if (algorithm === void 0) { algorithm = 'sha256'; }
var parts = hash.split('/');
var salt = parts[0];
return exports.doHash(text, algorithm, salt) === hash;
};
exports.doCompareHash = doCompareHash;
//# sourceMappingURL=encryption.js.map

@@ -1,1 +0,1 @@

{"version":3,"file":"encryption.js","sourceRoot":"","sources":["../../lib/encryption.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,6CAAiC;AAEjC,IAAM,SAAS,GAAG,aAAa,CAAC;AAChC,IAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,qBAAqB,IAAI,WAAW,CAAC;AAG5D,IAAM,OAAO,GAAG,UAAC,IAAY;IAChC,IAAI,EAAE,GAAQ,MAAM,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;IACrC,EAAE,GAAG,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IACrE,IAAM,GAAG,GAAG,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACrE,IAAM,MAAM,GAAG,MAAM,CAAC,cAAc,CAAC,SAAS,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC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