kaven-utils
Advanced tools
Comparing version 2.0.8 to 2.0.9
{ | ||
"name": "kaven-utils", | ||
"version": "2.0.8", | ||
"version": "2.0.9", | ||
"description": "Utils for Node.js.", | ||
@@ -48,3 +48,3 @@ "main": "index", | ||
"jszip": "^3.5.0", | ||
"kaven-basic": "^2.0.8", | ||
"kaven-basic": "^2.0.9", | ||
"morgan": "^1.10.0", | ||
@@ -51,0 +51,0 @@ "ncp": "^2.0.0", |
@@ -7,6 +7,6 @@ /******************************************************************** | ||
* @create: 2018-08-30 13:24:44.049 | ||
* @modify: 2020-07-08 13:58:28.887 | ||
* @version: 2.0.8 | ||
* @times: 18 | ||
* @lines: 75 | ||
* @modify: 2020-07-13 20:53:30.517 | ||
* @version: 2.0.9 | ||
* @times: 20 | ||
* @lines: 95 | ||
* @copyright: Copyright © 2018-2020 Kaven. All Rights Reserved. | ||
@@ -21,3 +21,3 @@ * @description: [description] | ||
* @since 1.0.5 | ||
* @version 2020-07-08 | ||
* @version 2020-07-13 | ||
*/ | ||
@@ -24,0 +24,0 @@ static readonly Logger: RequestHandler; |
@@ -8,6 +8,6 @@ "use strict"; | ||
* @create: 2018-08-30 13:24:44.049 | ||
* @modify: 2020-07-08 13:58:28.887 | ||
* @version: 2.0.8 | ||
* @times: 18 | ||
* @lines: 75 | ||
* @modify: 2020-07-13 20:53:30.517 | ||
* @version: 2.0.9 | ||
* @times: 20 | ||
* @lines: 95 | ||
* @copyright: Copyright © 2018-2020 Kaven. All Rights Reserved. | ||
@@ -39,16 +39,35 @@ * @description: [description] | ||
* @since 1.0.5 | ||
* @version 2020-07-08 | ||
* @version 2020-07-13 | ||
*/ | ||
KavenCommon.Logger = morgan(function (tokens, req, res) { | ||
try { | ||
var status = tokens.status(req, res); | ||
var statusCode_1 = Number(status); | ||
var color = function (str) { | ||
if (!isNaN(statusCode_1)) { | ||
if (statusCode_1 >= 200 && statusCode_1 < 300) { | ||
return KavenUtility_1.Chalk.green(str); | ||
} | ||
else if (statusCode_1 >= 300 && statusCode_1 < 400) { | ||
return KavenUtility_1.Chalk.cyan(str); | ||
} | ||
else { | ||
return KavenUtility_1.Chalk.red(str); | ||
} | ||
} | ||
return str; | ||
}; | ||
var part = [ | ||
"[" + kaven_basic_1.FormatDate() + "]", | ||
"[" + color(tokens.method(req, res)) + "]", | ||
" " + tokens.url(req, res) + " ", | ||
"[" + color(status) + "]", | ||
]; | ||
var log = [ | ||
"[" + 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"), | ||
"-", | ||
tokens["response-time"](req, res), | ||
"ms", | ||
].join(" "); | ||
part.join(kaven_basic_1.Strings.Empty), | ||
tokens["remote-addr"](req, res), | ||
tokens.res(req, res, "content-length") + " bytes", | ||
tokens["response-time"](req, res) + " ms", | ||
"HTTP/" + tokens["http-version"](req, res), | ||
].join(", "); | ||
if (console.logOrigin) { | ||
@@ -55,0 +74,0 @@ console.logOrigin(log); |
@@ -7,5 +7,5 @@ /******************************************************************** | ||
* @create: 2020-07-10 13:39:53.988 | ||
* @modify: 2020-07-11 12:52:09.365 | ||
* @version: 2.0.8 | ||
* @times: 16 | ||
* @modify: 2020-07-13 16:37:41.792 | ||
* @version: 2.0.9 | ||
* @times: 21 | ||
* @lines: 236 | ||
@@ -23,6 +23,4 @@ * @copyright: Copyright © 2020 Kaven. All Rights Reserved. | ||
export declare class KavenRSA { | ||
private readonly publicKey; | ||
private readonly privateKey; | ||
get PublicKey(): string | undefined; | ||
get PrivateKey(): string | undefined; | ||
readonly PublicKey: string | undefined; | ||
readonly PrivateKey: string | undefined; | ||
constructor(publicKey?: string, privateKey?: string); | ||
@@ -32,10 +30,10 @@ static Create(bits?: number, exponent?: number): KavenRSA; | ||
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; | ||
Sign(data: Buffer, algorithm?: string, padding?: number, saltLength?: number): Buffer; | ||
Verify(data: Buffer, signature: Buffer, algorithm?: string, padding?: number, saltLength?: 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; | ||
SignToString<T>(data: T, encoding?: BufferEncoding, algorithm?: string, padding?: number, saltLength?: number): string; | ||
VerifyFromString<T>(data: T, signature: string, encoding?: BufferEncoding, algorithm?: string, padding?: number, saltLength?: 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; | ||
} |
@@ -8,5 +8,5 @@ "use strict"; | ||
* @create: 2020-07-10 13:39:53.988 | ||
* @modify: 2020-07-11 12:52:09.365 | ||
* @version: 2.0.8 | ||
* @times: 16 | ||
* @modify: 2020-07-13 16:37:41.792 | ||
* @version: 2.0.9 | ||
* @times: 21 | ||
* @lines: 236 | ||
@@ -29,19 +29,5 @@ * @copyright: Copyright © 2020 Kaven. All Rights Reserved. | ||
function KavenRSA(publicKey, privateKey) { | ||
this.publicKey = publicKey; | ||
this.privateKey = privateKey; | ||
this.PublicKey = publicKey; | ||
this.PrivateKey = privateKey; | ||
} | ||
Object.defineProperty(KavenRSA.prototype, "PublicKey", { | ||
get: function () { | ||
return this.publicKey; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(KavenRSA.prototype, "PrivateKey", { | ||
get: function () { | ||
return this.privateKey; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
KavenRSA.Create = function (bits, exponent) { | ||
@@ -68,7 +54,7 @@ if (bits === void 0) { bits = 4096; } | ||
if (oaepHash === void 0) { oaepHash = "sha256"; } | ||
if (this.publicKey === undefined) { | ||
if (this.PublicKey === undefined) { | ||
throw new Error("publicKey is undefined"); | ||
} | ||
return crypto_1.publicEncrypt({ | ||
key: this.publicKey, | ||
key: this.PublicKey, | ||
padding: padding, | ||
@@ -81,7 +67,7 @@ oaepHash: oaepHash, | ||
if (oaepHash === void 0) { oaepHash = "sha256"; } | ||
if (this.privateKey === undefined) { | ||
if (this.PrivateKey === undefined) { | ||
throw new Error("privateKey is undefined"); | ||
} | ||
return crypto_1.privateDecrypt({ | ||
key: this.privateKey, | ||
key: this.PrivateKey, | ||
padding: padding, | ||
@@ -91,23 +77,27 @@ oaepHash: oaepHash, | ||
}; | ||
KavenRSA.prototype.Sign = function (data, algorithm, padding) { | ||
KavenRSA.prototype.Sign = function (data, algorithm, padding, saltLength) { | ||
if (algorithm === void 0) { algorithm = "sha256"; } | ||
if (padding === void 0) { padding = crypto_1.constants.RSA_PKCS1_PSS_PADDING; } | ||
if (this.privateKey === undefined) { | ||
if (saltLength === void 0) { saltLength = crypto_1.constants.RSA_PSS_SALTLEN_DIGEST; } | ||
if (this.PrivateKey === undefined) { | ||
throw new Error("privateKey is undefined"); | ||
} | ||
return crypto_1.sign(algorithm, data, { | ||
key: this.privateKey, | ||
key: this.PrivateKey, | ||
padding: padding, | ||
saltLength: saltLength, | ||
}); | ||
}; | ||
KavenRSA.prototype.Verify = function (data, signature, algorithm, padding) { | ||
KavenRSA.prototype.Verify = function (data, signature, algorithm, padding, saltLength) { | ||
if (algorithm === void 0) { algorithm = "sha256"; } | ||
if (padding === void 0) { padding = crypto_1.constants.RSA_PKCS1_PSS_PADDING; } | ||
if (this.publicKey === undefined) { | ||
if (saltLength === void 0) { saltLength = crypto_1.constants.RSA_PSS_SALTLEN_DIGEST; } | ||
if (this.PublicKey === undefined) { | ||
throw new Error("publicKey is undefined"); | ||
} | ||
var k = crypto_1.createPublicKey({ | ||
key: this.publicKey, | ||
key: this.PublicKey, | ||
}); | ||
k.padding = padding; | ||
k.saltLength = saltLength; | ||
return crypto_1.verify(algorithm, data, k, signature); | ||
@@ -129,13 +119,15 @@ }; | ||
}; | ||
KavenRSA.prototype.SignToString = function (data, encoding, algorithm, padding) { | ||
KavenRSA.prototype.SignToString = function (data, encoding, algorithm, padding, saltLength) { | ||
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); | ||
if (saltLength === void 0) { saltLength = crypto_1.constants.RSA_PSS_SALTLEN_DIGEST; } | ||
return this.Sign(Buffer.from(JSON.stringify(data)), algorithm, padding, saltLength).toString(encoding); | ||
}; | ||
KavenRSA.prototype.VerifyFromString = function (data, signature, encoding, algorithm, padding) { | ||
KavenRSA.prototype.VerifyFromString = function (data, signature, encoding, algorithm, padding, saltLength) { | ||
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); | ||
if (saltLength === void 0) { saltLength = crypto_1.constants.RSA_PSS_SALTLEN_DIGEST; } | ||
return this.Verify(Buffer.from(JSON.stringify(data)), Buffer.from(signature, encoding), algorithm, padding, saltLength); | ||
}; | ||
@@ -142,0 +134,0 @@ KavenRSA.prototype.EncryptBigData = function (data, encoding, padding, oaepHash) { |
221380
5595
Updatedkaven-basic@^2.0.9