Socket
Socket
Sign inDemoInstall

kaven-utils

Package Overview
Dependencies
137
Maintainers
1
Versions
101
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.7 to 2.0.8

src/KavenCrypto.d.ts

11

index.d.ts

@@ -7,6 +7,6 @@ /********************************************************************

* @create: 2018-08-25 08:19:55.120
* @modify: 2020-06-22 13:24:46.562
* @version: 2.0.6
* @times: 50
* @lines: 104
* @modify: 2020-07-11 09:17:40.791
* @version: 2.0.8
* @times: 53
* @lines: 105
* @copyright: Copyright © 2018-2020 Kaven. All Rights Reserved.

@@ -64,3 +64,2 @@ * @description: Utils for Node.js.

export * from "./src/KavenLog";
export * from "./src/KavenRSA";
export * from "./src/KavenSSO/KavenSSO";

@@ -70,2 +69,4 @@ export * from "./src/KavenSSO/KavenSSOServer";

export * from "./src/MailConfig";
export * from "./src/KavenCrypto";
export * from "./src/KavenRSA";
export * from "./src/KavenAuthenticate/KavenAuthentication";

@@ -72,0 +73,0 @@ export * from "./src/KavenAuthenticate/KavenBasicAuthentication";

@@ -8,6 +8,6 @@ "use strict";

* @create: 2018-08-25 08:19:55.120
* @modify: 2020-06-22 13:24:46.562
* @version: 2.0.6
* @times: 50
* @lines: 104
* @modify: 2020-07-11 09:17:40.791
* @version: 2.0.8
* @times: 53
* @lines: 105
* @copyright: Copyright © 2018-2020 Kaven. All Rights Reserved.

@@ -71,3 +71,2 @@ * @description: Utils for Node.js.

__exportStar(require("./src/KavenLog"), exports);
__exportStar(require("./src/KavenRSA"), exports);
__exportStar(require("./src/KavenSSO/KavenSSO"), exports);

@@ -77,2 +76,4 @@ __exportStar(require("./src/KavenSSO/KavenSSOServer"), exports);

__exportStar(require("./src/MailConfig"), exports);
__exportStar(require("./src/KavenCrypto"), exports);
__exportStar(require("./src/KavenRSA"), exports);
__exportStar(require("./src/KavenAuthenticate/KavenAuthentication"), exports);

@@ -79,0 +80,0 @@ __exportStar(require("./src/KavenAuthenticate/KavenBasicAuthentication"), exports);

{
"name": "kaven-utils",
"version": "2.0.7",
"version": "2.0.8",
"description": "Utils for Node.js.",

@@ -44,12 +44,9 @@ "main": "index",

"file-type": "^14.6.2",
"forever": "^3.0.0",
"ftp": "^0.3.10",
"iconv-lite": "^0.6.0",
"iconv-lite": "^0.6.2",
"jsonwebtoken": "^8.5.1",
"jszip": "^3.5.0",
"kaven-basic": "^2.0.7",
"mkdirp": "^1.0.4",
"kaven-basic": "^2.0.8",
"morgan": "^1.10.0",
"ncp": "^2.0.0",
"node-rsa": "^1.0.8",
"node-schedule": "^1.3.2",

@@ -56,0 +53,0 @@ "nodemailer": "^6.4.10",

@@ -7,6 +7,6 @@ /********************************************************************

* @create: 2018-08-30 13:24:44.049
* @modify: 2020-06-02 17:23:45.180
* @version: 2.0.5
* @times: 17
* @lines: 74
* @modify: 2020-07-08 13:58:28.887
* @version: 2.0.8
* @times: 18
* @lines: 75
* @copyright: Copyright © 2018-2020 Kaven. All Rights Reserved.

@@ -20,4 +20,4 @@ * @description: [description]

/**
* @version 1.0.0
* @since 1.0.5
* @version 2020-07-08
*/

@@ -24,0 +24,0 @@ static readonly Logger: RequestHandler;

@@ -8,6 +8,6 @@ "use strict";

* @create: 2018-08-30 13:24:44.049
* @modify: 2020-06-02 17:23:45.180
* @version: 2.0.5
* @times: 17
* @lines: 74
* @modify: 2020-07-08 13:58:28.887
* @version: 2.0.8
* @times: 18
* @lines: 75
* @copyright: Copyright © 2018-2020 Kaven. All Rights Reserved.

@@ -38,4 +38,4 @@ * @description: [description]

/**
* @version 1.0.0
* @since 1.0.5
* @version 2020-07-08
*/

@@ -45,5 +45,6 @@ KavenCommon.Logger = morgan(function (tokens, req, res) {

var log = [
"[" + KavenCommon.Chalk.green(kaven_basic_1.FormatDate()) + "][" + tokens.method(req, res) + "]",
"[" + KavenCommon.Chalk.green(kaven_basic_1.FormatDate(undefined, kaven_basic_1.DateTimeFormat.FullDataTime)) + "][" + tokens.method(req, res) + "]",
KavenCommon.Chalk.blue(tokens.url(req, res)),
"[" + KavenUtility_1.GetColoredStatus(tokens.status(req, res)) + "]",
"[" + req.ip + "]",
tokens.res(req, res, "content-length"),

@@ -50,0 +51,0 @@ "-",

@@ -6,29 +6,34 @@ /********************************************************************

* @file: [Kaven-Utils] /src/KavenRSA.ts
* @create: 2018-10-19 13:36:55.688
* @modify: 2020-06-02 17:23:45.184
* @version: 2.0.5
* @times: 14
* @lines: 75
* @copyright: Copyright © 2018-2020 Kaven. All Rights Reserved.
* @create: 2020-07-10 13:39:53.988
* @modify: 2020-07-11 12:52:09.365
* @version: 2.0.8
* @times: 16
* @lines: 236
* @copyright: Copyright © 2020 Kaven. All Rights Reserved.
* @description: [description]
* @license: [license]
********************************************************************/
/// <reference types="node" />
/**
*
* @version 1.1.17
* @since 2018-10-19
* crypto wrap
* @since 2.0.8
* @version 2020-07-10
*/
export declare class KavenRSA {
get Public(): string;
get Private(): string;
get KeySizeInBits(): number;
get MaxMessageSizeInBytes(): number;
private readonly publicKey;
private readonly privateKey;
get PublicKey(): string | undefined;
get PrivateKey(): string | undefined;
constructor(publicKey?: string, privateKey?: string);
static Create(bits?: number, exponent?: number): KavenRSA;
static CreateFromString(str: string): KavenRSA;
static CreateFromFile(file: string): KavenRSA;
private readonly nodeRSAInstance;
Encrypt(data: string): string;
Decrypt(encryptedData: string): string;
Sign(data: string): string;
Verify(signedData: string, signature: string): boolean;
Encrypt(data: Buffer, padding?: number, oaepHash?: string): Buffer;
Decrypt(data: Buffer, padding?: number, oaepHash?: string): Buffer;
Sign(data: Buffer, algorithm?: string, padding?: number): Buffer;
Verify(data: Buffer, signature: Buffer, algorithm?: string, padding?: number): boolean;
EncryptToString<T>(data: T, encoding?: BufferEncoding, padding?: number, oaepHash?: string): string;
DecryptFromString<T = any>(data: string, encoding?: BufferEncoding, padding?: number, oaepHash?: string): T;
SignToString<T>(data: T, encoding?: BufferEncoding, algorithm?: string, padding?: number): string;
VerifyFromString<T>(data: T, signature: string, encoding?: BufferEncoding, algorithm?: string, padding?: number): boolean;
EncryptBigData<T>(data: T, encoding?: BufferEncoding, padding?: number, oaepHash?: string): string;
DecryptBigData<T = any>(data: string, encoding?: BufferEncoding, padding?: number, oaepHash?: string): T;
}

@@ -7,8 +7,8 @@ "use strict";

* @file: [Kaven-Utils] /src/KavenRSA.ts
* @create: 2018-10-19 13:36:55.688
* @modify: 2020-06-02 17:23:45.184
* @version: 2.0.5
* @times: 14
* @lines: 75
* @copyright: Copyright © 2018-2020 Kaven. All Rights Reserved.
* @create: 2020-07-10 13:39:53.988
* @modify: 2020-07-11 12:52:09.365
* @version: 2.0.8
* @times: 16
* @lines: 236
* @copyright: Copyright © 2020 Kaven. All Rights Reserved.
* @description: [description]

@@ -19,16 +19,18 @@ * @license: [license]

exports.KavenRSA = void 0;
var fs_1 = require("fs");
var NodeRSA = require("node-rsa");
var crypto_1 = require("crypto");
var KavenCrypto_1 = require("./KavenCrypto");
var kaven_basic_1 = require("kaven-basic");
/**
*
* @version 1.1.17
* @since 2018-10-19
* crypto wrap
* @since 2.0.8
* @version 2020-07-10
*/
var KavenRSA = /** @class */ (function () {
function KavenRSA() {
this.nodeRSAInstance = new NodeRSA();
function KavenRSA(publicKey, privateKey) {
this.publicKey = publicKey;
this.privateKey = privateKey;
}
Object.defineProperty(KavenRSA.prototype, "Public", {
Object.defineProperty(KavenRSA.prototype, "PublicKey", {
get: function () {
return this.nodeRSAInstance.exportKey("public");
return this.publicKey;
},

@@ -38,5 +40,5 @@ enumerable: false,

});
Object.defineProperty(KavenRSA.prototype, "Private", {
Object.defineProperty(KavenRSA.prototype, "PrivateKey", {
get: function () {
return this.nodeRSAInstance.exportKey("private");
return this.privateKey;
},

@@ -46,45 +48,119 @@ enumerable: false,

});
Object.defineProperty(KavenRSA.prototype, "KeySizeInBits", {
get: function () {
return this.nodeRSAInstance.getKeySize();
},
enumerable: false,
configurable: true
});
Object.defineProperty(KavenRSA.prototype, "MaxMessageSizeInBytes", {
get: function () {
return this.nodeRSAInstance.getMaxMessageSize();
},
enumerable: false,
configurable: true
});
KavenRSA.Create = function (bits, exponent) {
if (bits === void 0) { bits = 4096; }
if (exponent === void 0) { exponent = 65537; }
var instance = new KavenRSA();
instance.nodeRSAInstance.generateKeyPair(bits, exponent);
return instance;
var keys = crypto_1.generateKeyPairSync("rsa", {
modulusLength: bits,
publicExponent: exponent,
});
var publicKey = keys.publicKey.export({
type: "pkcs1",
format: "pem",
}).toString();
var privateKey = keys.privateKey.export({
type: "pkcs8",
format: "pem",
}).toString();
return new KavenRSA(publicKey, privateKey);
};
KavenRSA.CreateFromString = function (str) {
var instance = new KavenRSA();
instance.nodeRSAInstance.importKey(str);
return instance;
// #region Core Methods
KavenRSA.prototype.Encrypt = function (data, padding, oaepHash) {
if (padding === void 0) { padding = crypto_1.constants.RSA_PKCS1_OAEP_PADDING; }
if (oaepHash === void 0) { oaepHash = "sha256"; }
if (this.publicKey === undefined) {
throw new Error("publicKey is undefined");
}
return crypto_1.publicEncrypt({
key: this.publicKey,
padding: padding,
oaepHash: oaepHash,
}, data);
};
KavenRSA.CreateFromFile = function (file) {
return KavenRSA.CreateFromString(fs_1.readFileSync(file, "utf8"));
KavenRSA.prototype.Decrypt = function (data, padding, oaepHash) {
if (padding === void 0) { padding = crypto_1.constants.RSA_PKCS1_OAEP_PADDING; }
if (oaepHash === void 0) { oaepHash = "sha256"; }
if (this.privateKey === undefined) {
throw new Error("privateKey is undefined");
}
return crypto_1.privateDecrypt({
key: this.privateKey,
padding: padding,
oaepHash: oaepHash,
}, data);
};
KavenRSA.prototype.Encrypt = function (data) {
return this.nodeRSAInstance.encrypt(data, "base64");
KavenRSA.prototype.Sign = function (data, algorithm, padding) {
if (algorithm === void 0) { algorithm = "sha256"; }
if (padding === void 0) { padding = crypto_1.constants.RSA_PKCS1_PSS_PADDING; }
if (this.privateKey === undefined) {
throw new Error("privateKey is undefined");
}
return crypto_1.sign(algorithm, data, {
key: this.privateKey,
padding: padding,
});
};
KavenRSA.prototype.Decrypt = function (encryptedData) {
return this.nodeRSAInstance.decrypt(encryptedData).toString("utf8");
KavenRSA.prototype.Verify = function (data, signature, algorithm, padding) {
if (algorithm === void 0) { algorithm = "sha256"; }
if (padding === void 0) { padding = crypto_1.constants.RSA_PKCS1_PSS_PADDING; }
if (this.publicKey === undefined) {
throw new Error("publicKey is undefined");
}
var k = crypto_1.createPublicKey({
key: this.publicKey,
});
k.padding = padding;
return crypto_1.verify(algorithm, data, k, signature);
};
KavenRSA.prototype.Sign = function (data) {
return this.nodeRSAInstance.sign(data, "base64");
// #endregion
// #region Helper Methods
KavenRSA.prototype.EncryptToString = function (data, encoding, padding, oaepHash) {
if (encoding === void 0) { encoding = "base64"; }
if (padding === void 0) { padding = crypto_1.constants.RSA_PKCS1_OAEP_PADDING; }
if (oaepHash === void 0) { oaepHash = "sha256"; }
return this.Encrypt(Buffer.from(JSON.stringify(data)), padding, oaepHash).toString(encoding);
};
KavenRSA.prototype.Verify = function (signedData, signature) {
return this.nodeRSAInstance.verify(signedData, signature, undefined, "base64");
KavenRSA.prototype.DecryptFromString = function (data, encoding, padding, oaepHash) {
if (encoding === void 0) { encoding = "base64"; }
if (padding === void 0) { padding = crypto_1.constants.RSA_PKCS1_OAEP_PADDING; }
if (oaepHash === void 0) { oaepHash = "sha256"; }
return JSON.parse(this.Decrypt(Buffer.from(data, encoding), padding, oaepHash).toString());
};
KavenRSA.prototype.SignToString = function (data, encoding, algorithm, padding) {
if (encoding === void 0) { encoding = "base64"; }
if (algorithm === void 0) { algorithm = "sha256"; }
if (padding === void 0) { padding = crypto_1.constants.RSA_PKCS1_PSS_PADDING; }
return this.Sign(Buffer.from(JSON.stringify(data)), algorithm, padding).toString(encoding);
};
KavenRSA.prototype.VerifyFromString = function (data, signature, encoding, algorithm, padding) {
if (encoding === void 0) { encoding = "base64"; }
if (algorithm === void 0) { algorithm = "sha256"; }
if (padding === void 0) { padding = crypto_1.constants.RSA_PKCS1_PSS_PADDING; }
return this.Verify(Buffer.from(JSON.stringify(data)), Buffer.from(signature, encoding), algorithm, padding);
};
KavenRSA.prototype.EncryptBigData = function (data, encoding, padding, oaepHash) {
if (encoding === void 0) { encoding = "base64"; }
if (padding === void 0) { padding = crypto_1.constants.RSA_PKCS1_OAEP_PADDING; }
if (oaepHash === void 0) { oaepHash = "sha256"; }
var password = KavenCrypto_1.GenerateEncryptPassword();
var dataStr = JSON.stringify(data);
var encryptedData = KavenCrypto_1.EncryptString(dataStr, password);
var encryptedPassword = this.EncryptToString(password, encoding, padding, oaepHash);
return kaven_basic_1.StringArray2String(encryptedData, encryptedPassword);
};
KavenRSA.prototype.DecryptBigData = function (data, encoding, padding, oaepHash) {
if (encoding === void 0) { encoding = "base64"; }
if (padding === void 0) { padding = crypto_1.constants.RSA_PKCS1_OAEP_PADDING; }
if (oaepHash === void 0) { oaepHash = "sha256"; }
var items = kaven_basic_1.String2StringArray(data);
if (items && items.length === 2) {
var encryptedData = items[0];
var encryptedPassword = items[1];
var password = this.DecryptFromString(encryptedPassword, encoding, padding, oaepHash);
var dataStr = KavenCrypto_1.DecryptString(encryptedData, password);
return JSON.parse(dataStr);
}
throw new Error("DecryptBigData failed");
};
return KavenRSA;
}());
exports.KavenRSA = KavenRSA;

@@ -7,6 +7,6 @@ /********************************************************************

* @create: 2018-08-25 08:19:55.120
* @modify: 2020-07-06 16:12:47.455
* @version: 2.0.7
* @times: 184
* @lines: 2187
* @modify: 2020-07-11 12:52:09.367
* @version: 2.0.8
* @times: 199
* @lines: 2006
* @copyright: Copyright © 2018-2020 Kaven. All Rights Reserved.

@@ -35,13 +35,11 @@ * @description: Utils for Node.js.

import AnsiUp from "ansi_up";
import * as chalk from "chalk";
import { ExecOptions, SpawnOptionsWithoutStdio } from "child_process";
import { FileTypeResult } from "file-type";
import * as JWT from "jsonwebtoken";
import * as schedule from "node-schedule";
import * as pem from "pem";
import { IndexObject, LogLevel, MailOption } from "kaven-basic";
import { Options as ncpOptions } from "ncp";
import { Job } from "node-schedule";
import { CertificateCreationOptions, CertificateCreationResult } from "pem";
import { IExecOptions, IExternalIPRule, IHTTPResponse } from "./Interfaces";
import { MailConfig } from "./MailConfig";
export declare type Job = schedule.Job;
/**

@@ -61,3 +59,3 @@ * @since 1.1.21

*/
export declare const Chalk: chalk.Chalk;
export declare const Chalk: import("chalk").Chalk;
/**

@@ -107,7 +105,2 @@ * @since IExternalIPRule

/**
* @version 1.0.1
* @since 1.0.5
*/
export declare function FindLogFile(): Promise<string>;
/**
* 2019-08-05:

@@ -124,9 +117,9 @@ * remove default value "./data/logs/" for `backupFolder`;

/**
*
* @param file
* @param html
* @version 1.0.1
* @since 1.0.5
* 2019-08-05:
* add param: `logFile`
* @param overBytes
* @since 1.0.9
* @version 2020-07-11
*/
export declare function GetLogContent(file?: string, html?: boolean): Promise<any>;
export declare function ResetLogFileIf(overBytes?: number, logFile?: string): Promise<boolean>;
/**

@@ -291,3 +284,3 @@ *

*/
export declare function StartSchedule(func: () => void, year?: number | number[], month?: number | number[], date?: number | number[], dayOfWeek?: number | number[], hour?: number | number[], minute?: number | number[], second?: number | number[]): schedule.Job;
export declare function StartSchedule(func: () => void, year?: number | number[], month?: number | number[], date?: number | number[], dayOfWeek?: number | number[], hour?: number | number[], minute?: number | number[], second?: number | number[]): Job;
/**

@@ -300,3 +293,3 @@ *

*/
export declare function StartScheduleLikeCron(func: () => void, rule: string): schedule.Job;
export declare function StartScheduleLikeCron(func: () => void, rule: string): Job;
/**

@@ -338,9 +331,9 @@ *

* @export
* @param {pem.CertificateCreationOptions} [options={ days: 1, selfSigned: true }]
* @param {CertificateCreationOptions} [options={ days: 1, selfSigned: true }]
* @returns
* @see {@link https://www.deineagentur.com/projects/pem/module-pem.html#.createCertificate}
* @see {@link https://www.deineagentur.com/projects/pem/module-html#.createCertificate}
* @version 1.0.0
* @since 1.0.6
*/
export declare function CreateCertificate(options?: pem.CertificateCreationOptions): Promise<pem.CertificateCreationResult>;
export declare function CreateCertificate(options?: CertificateCreationOptions): Promise<CertificateCreationResult>;
/**

@@ -410,14 +403,6 @@ *

/**
* 2019-08-05:
* add param: `logFile`
* @param overBytes
* @version 1.0.0
* @since 1.0.9
*/
export declare function ResetLogFileIf(overBytes?: number, logFile?: string): Promise<boolean>;
/**
*
* @param dir
* @version 1.0.0
* @since 1.0.9
* @version 2020-07-11
*/

@@ -428,6 +413,6 @@ export declare function MakeDirectory(dir: string): Promise<string | undefined>;

* @param dir
* @version 1.0.0
* @since 1.0.9
* @version 2020-07-11
*/
export declare function MakeDirectorySync(dir: string): string | undefined;
export declare function MakeDirectorySync(dir: string): string;
/**

@@ -627,5 +612,5 @@ *

/**
* Simple wrap for fs.existsSync
* Simple wrap for existsSync
* @param fullPath
* @see https://nodejs.org/docs/latest-v8.x/api/fs.html#fs_fs_existssync_path
* @see https://nodejs.org/docs/latest-v8.x/api/html#fs_fs_existssync_path
* @since 1.1.20

@@ -677,29 +662,1 @@ * @since 2018-10-28

export declare function InitializeTextLogger(stdoutFile: string, stderrFile: string): void;
/**
*
* @param strArray
*/
export declare function StringArray2String(strArray: string[]): string;
/**
*
* @param str
*/
export declare function String2StringArray(str: string): string[] | undefined;
/**
*
*/
export declare function GenerateEncryptPassword(keySize?: number, ivSize?: number): string;
/**
*
* @param str some clear text data
* @param password Password used to generate key
* @param algorithm
*/
export declare function EncryptString(str: string, password: string, algorithm?: string): string | undefined;
/**
*
* @param encryptedStr
* @param password Password used to generate key
* @param algorithm
*/
export declare function DecryptString(encryptedStr: string, password: string, algorithm?: string): string | undefined;

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc