@nivinjoseph/n-sec 5.0.5 → 6.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.vscode/settings.json +111 -0
- package/.yarn/releases/yarn-4.0.2.cjs +893 -0
- package/.yarnrc.yml +3 -0
- package/dist/api-security/alg-type.d.ts +1 -0
- package/dist/api-security/alg-type.d.ts.map +1 -0
- package/dist/api-security/alg-type.js +2 -5
- package/dist/api-security/alg-type.js.map +1 -1
- package/dist/api-security/claim.d.ts +1 -0
- package/dist/api-security/claim.d.ts.map +1 -0
- package/dist/api-security/claim.js +5 -9
- package/dist/api-security/claim.js.map +1 -1
- package/dist/api-security/claims-identity.d.ts +2 -1
- package/dist/api-security/claims-identity.d.ts.map +1 -0
- package/dist/api-security/claims-identity.js +4 -8
- package/dist/api-security/claims-identity.js.map +1 -1
- package/dist/api-security/expired-token-exception.d.ts +1 -0
- package/dist/api-security/expired-token-exception.d.ts.map +1 -0
- package/dist/api-security/expired-token-exception.js +5 -9
- package/dist/api-security/expired-token-exception.js.map +1 -1
- package/dist/api-security/invalid-token-exception.d.ts +1 -0
- package/dist/api-security/invalid-token-exception.d.ts.map +1 -0
- package/dist/api-security/invalid-token-exception.js +7 -11
- package/dist/api-security/invalid-token-exception.js.map +1 -1
- package/dist/api-security/json-web-token.d.ts +3 -2
- package/dist/api-security/json-web-token.d.ts.map +1 -0
- package/dist/api-security/json-web-token.js +39 -43
- package/dist/api-security/json-web-token.js.map +1 -1
- package/dist/api-security/security-token.d.ts +1 -0
- package/dist/api-security/security-token.d.ts.map +1 -0
- package/dist/api-security/security-token.js +6 -10
- package/dist/api-security/security-token.js.map +1 -1
- package/dist/bin.d.ts +1 -0
- package/dist/bin.d.ts.map +1 -0
- package/dist/bin.js +16 -20
- package/dist/bin.js.map +1 -1
- package/dist/crypto/asymmetric-encryption.d.ts +2 -0
- package/dist/crypto/asymmetric-encryption.d.ts.map +1 -0
- package/dist/crypto/asymmetric-encryption.js +1 -1
- package/dist/crypto/asymmetric-encryption.js.map +1 -1
- package/dist/crypto/crypto-exception.d.ts +1 -0
- package/dist/crypto/crypto-exception.d.ts.map +1 -0
- package/dist/crypto/crypto-exception.js +2 -6
- package/dist/crypto/crypto-exception.js.map +1 -1
- package/dist/crypto/digital-signature.d.ts +2 -0
- package/dist/crypto/digital-signature.d.ts.map +1 -0
- package/dist/crypto/digital-signature.js +1 -1
- package/dist/crypto/digital-signature.js.map +1 -1
- package/dist/crypto/hash.d.ts +1 -0
- package/dist/crypto/hash.d.ts.map +1 -0
- package/dist/crypto/hash.js +7 -11
- package/dist/crypto/hash.js.map +1 -1
- package/dist/crypto/hmac.d.ts +1 -0
- package/dist/crypto/hmac.d.ts.map +1 -0
- package/dist/crypto/hmac.js +6 -10
- package/dist/crypto/hmac.js.map +1 -1
- package/dist/crypto/symmetric-encryption.d.ts +1 -0
- package/dist/crypto/symmetric-encryption.d.ts.map +1 -0
- package/dist/crypto/symmetric-encryption.js +13 -17
- package/dist/crypto/symmetric-encryption.js.map +1 -1
- package/dist/index.d.ts +13 -12
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +17 -28
- package/dist/index.js.map +1 -1
- package/dist/tsconfig.json +2 -1
- package/eslint.config.js +591 -0
- package/package.json +24 -24
- package/src/api-security/claims-identity.ts +1 -1
- package/src/api-security/json-web-token.ts +21 -21
- package/src/bin.ts +2 -1
- package/src/crypto/hash.ts +9 -9
- package/src/crypto/hmac.ts +7 -7
- package/src/crypto/symmetric-encryption.ts +11 -11
- package/src/index.ts +17 -18
- package/test/asymmetric-encryption.test.ts +37 -37
- package/test/digital-signature.test.ts +22 -22
- package/test/hash.test.ts +109 -109
- package/test/hmac.test.ts +56 -55
- package/test/json-web-token.test.ts +95 -95
- package/test/other.test.ts +8 -7
- package/test/symmetric-encryption.test.ts +49 -48
- package/tsconfig.json +8 -5
- package/.eslintignore +0 -2
- package/.eslintrc +0 -335
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { Claim } from "./claim";
|
|
2
|
-
import { InvalidOperationException } from "@nivinjoseph/n-exception";
|
|
3
1
|
import { given } from "@nivinjoseph/n-defensive";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
import {
|
|
2
|
+
import { InvalidOperationException } from "@nivinjoseph/n-exception";
|
|
3
|
+
import { Hmac } from "./../crypto/hmac.js";
|
|
4
|
+
import { AlgType } from "./alg-type.js";
|
|
5
|
+
import { Claim } from "./claim.js";
|
|
6
|
+
import { InvalidTokenException } from "./invalid-token-exception.js";
|
|
7
|
+
// import { DigitalSignature } from "./../crypto/digital-signature.js";
|
|
8
|
+
import { ExpiredTokenException } from "./expired-token-exception.js";
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
// public
|
|
@@ -18,7 +18,7 @@ export class JsonWebToken
|
|
|
18
18
|
private readonly _expiry: number;
|
|
19
19
|
private readonly _claims: Array<Claim>;
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
|
|
22
22
|
public get issuer(): string { return this._issuer; }
|
|
23
23
|
public get algType(): AlgType { return this._algType; }
|
|
24
24
|
public get key(): string { return this._key; }
|
|
@@ -26,8 +26,8 @@ export class JsonWebToken
|
|
|
26
26
|
public get expiry(): number { return this._expiry; }
|
|
27
27
|
public get isExpired(): boolean { return this._expiry <= Date.now(); }
|
|
28
28
|
public get claims(): ReadonlyArray<Claim> { return this._claims; }
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
|
|
30
|
+
|
|
31
31
|
private constructor(issuer: string, algType: AlgType, key: string, isFullKey: boolean, expiry: number,
|
|
32
32
|
claims: Array<Claim>)
|
|
33
33
|
{
|
|
@@ -38,7 +38,7 @@ export class JsonWebToken
|
|
|
38
38
|
given(expiry, "expiry").ensureHasValue().ensureIsNumber();
|
|
39
39
|
given(claims, "claims").ensureHasValue().ensureIsArray()
|
|
40
40
|
.ensure(t => t.isNotEmpty, "cannot be empty");
|
|
41
|
-
|
|
41
|
+
|
|
42
42
|
this._issuer = issuer.trim();
|
|
43
43
|
this._algType = algType;
|
|
44
44
|
this._key = key.trim();
|
|
@@ -46,7 +46,7 @@ export class JsonWebToken
|
|
|
46
46
|
this._expiry = expiry;
|
|
47
47
|
this._claims = [...claims];
|
|
48
48
|
}
|
|
49
|
-
|
|
49
|
+
|
|
50
50
|
public static fromClaims(issuer: string, algType: AlgType, key: string, expiry: number,
|
|
51
51
|
claims: Array<Claim>): JsonWebToken
|
|
52
52
|
{
|
|
@@ -132,33 +132,33 @@ export class JsonWebToken
|
|
|
132
132
|
const obj = JSON.parse(json) as object;
|
|
133
133
|
return obj;
|
|
134
134
|
}
|
|
135
|
-
|
|
135
|
+
|
|
136
136
|
public generateToken(): string
|
|
137
137
|
{
|
|
138
138
|
if (!this._isfullKey)
|
|
139
|
-
throw new InvalidOperationException("generating token using an instance created from token");
|
|
140
|
-
|
|
139
|
+
throw new InvalidOperationException("generating token using an instance created from token");
|
|
140
|
+
|
|
141
141
|
const header: Header = {
|
|
142
142
|
iss: this._issuer,
|
|
143
143
|
alg: this._algType,
|
|
144
144
|
exp: this._expiry
|
|
145
145
|
};
|
|
146
|
-
|
|
146
|
+
|
|
147
147
|
const body: any = {};
|
|
148
148
|
this._claims.forEach(t => body[t.type] = t.value);
|
|
149
|
-
|
|
149
|
+
|
|
150
150
|
const headerAndBody = this._toHex(header) + "." + this._toHex(body);
|
|
151
|
-
|
|
151
|
+
|
|
152
152
|
// let signature = this._algType === AlgType.hmac
|
|
153
153
|
// ? await Hmac.create(this._key, headerAndBody)
|
|
154
154
|
// : await DigitalSignature.sign(this._key, headerAndBody);
|
|
155
|
-
|
|
155
|
+
|
|
156
156
|
const signature = Hmac.create(this._key, headerAndBody);
|
|
157
|
-
|
|
157
|
+
|
|
158
158
|
const token = headerAndBody + "." + signature;
|
|
159
159
|
return token;
|
|
160
160
|
}
|
|
161
|
-
|
|
161
|
+
|
|
162
162
|
private _toHex(obj: object): string
|
|
163
163
|
{
|
|
164
164
|
const json = JSON.stringify(obj);
|
package/src/bin.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
// import { given } from "@nivinjoseph/n-defensive";
|
|
4
4
|
import { TypeHelper } from "@nivinjoseph/n-util";
|
|
5
|
-
import { SymmetricEncryption } from "./crypto/symmetric-encryption";
|
|
5
|
+
import { SymmetricEncryption } from "./crypto/symmetric-encryption.js";
|
|
6
6
|
|
|
7
7
|
enum SupportedCommands
|
|
8
8
|
{
|
|
@@ -17,6 +17,7 @@ async function executeCommand(command: SupportedCommands): Promise<void>
|
|
|
17
17
|
|
|
18
18
|
switch (command)
|
|
19
19
|
{
|
|
20
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
20
21
|
case SupportedCommands.generateSymmetricKey:
|
|
21
22
|
{
|
|
22
23
|
const key = await SymmetricEncryption.generateKey();
|
package/src/crypto/hash.ts
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
import { given } from "@nivinjoseph/n-defensive";
|
|
2
|
-
import
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
// public
|
|
6
6
|
export class Hash
|
|
7
7
|
{
|
|
8
8
|
private constructor() { }
|
|
9
|
-
|
|
9
|
+
|
|
10
10
|
|
|
11
11
|
public static create(value: string): string
|
|
12
12
|
{
|
|
13
13
|
given(value, "value").ensureHasValue().ensureIsString();
|
|
14
14
|
value = value.trim();
|
|
15
|
-
|
|
16
|
-
const hash =
|
|
15
|
+
|
|
16
|
+
const hash = createHash("sha512");
|
|
17
17
|
hash.update(value, "utf8");
|
|
18
18
|
return hash.digest("hex").toUpperCase();
|
|
19
19
|
}
|
|
20
|
-
|
|
20
|
+
|
|
21
21
|
public static createUsingSalt(value: string, salt: string): string
|
|
22
22
|
{
|
|
23
23
|
given(value, "value").ensureHasValue().ensureIsString();
|
|
@@ -25,7 +25,7 @@ export class Hash
|
|
|
25
25
|
|
|
26
26
|
value = value.trim();
|
|
27
27
|
salt = salt.trim();
|
|
28
|
-
|
|
28
|
+
|
|
29
29
|
const reverse = (val: string): string =>
|
|
30
30
|
{
|
|
31
31
|
let rev = "";
|
|
@@ -33,14 +33,14 @@ export class Hash
|
|
|
33
33
|
rev = val[i] + rev;
|
|
34
34
|
return rev;
|
|
35
35
|
};
|
|
36
|
-
|
|
36
|
+
|
|
37
37
|
const valueReverse = reverse(value);
|
|
38
38
|
const saltReverse = reverse(salt);
|
|
39
39
|
|
|
40
40
|
// const saltedValue = "{1}{0}{2}{1}{3}{1}{2}".format(value, salt, valueReverse, saltReverse);
|
|
41
|
-
|
|
41
|
+
|
|
42
42
|
const saltedValue = `${salt}${value}${valueReverse}${salt}${saltReverse}${salt}${valueReverse}`;
|
|
43
|
-
|
|
43
|
+
|
|
44
44
|
return Hash.create(saltedValue);
|
|
45
45
|
}
|
|
46
46
|
}
|
package/src/crypto/hmac.ts
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
import { given } from "@nivinjoseph/n-defensive";
|
|
2
|
-
import
|
|
2
|
+
import { createHmac } from "node:crypto";
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
// public
|
|
6
6
|
export class Hmac
|
|
7
7
|
{
|
|
8
8
|
private constructor() { }
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
|
|
10
|
+
|
|
11
11
|
public static create(key: string, value: string): string
|
|
12
12
|
{
|
|
13
13
|
given(key, "key").ensureHasValue().ensureIsString();
|
|
14
14
|
given(value, "value").ensureHasValue().ensureIsString();
|
|
15
|
-
|
|
15
|
+
|
|
16
16
|
key = key.trim();
|
|
17
17
|
value = value.trim();
|
|
18
|
-
|
|
19
|
-
const hmac =
|
|
20
|
-
|
|
18
|
+
|
|
19
|
+
const hmac = createHmac("sha256", Buffer.from(key, "hex"));
|
|
20
|
+
|
|
21
21
|
hmac.update(value, "utf8");
|
|
22
22
|
return hmac.digest("hex").toUpperCase();
|
|
23
23
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import * as Crypto from "crypto";
|
|
2
|
-
import { CryptoException } from "./crypto-exception";
|
|
3
1
|
import { given } from "@nivinjoseph/n-defensive";
|
|
2
|
+
import { createCipheriv, createDecipheriv, randomBytes } from "node:crypto";
|
|
3
|
+
import { CryptoException } from "./crypto-exception.js";
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
// public
|
|
@@ -8,12 +8,12 @@ export class SymmetricEncryption
|
|
|
8
8
|
{
|
|
9
9
|
private constructor() { }
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
|
|
12
12
|
public static generateKey(): Promise<string>
|
|
13
13
|
{
|
|
14
14
|
return new Promise<string>((resolve, reject) =>
|
|
15
15
|
{
|
|
16
|
-
|
|
16
|
+
randomBytes(32, (err, buf) =>
|
|
17
17
|
{
|
|
18
18
|
if (err)
|
|
19
19
|
{
|
|
@@ -25,7 +25,7 @@ export class SymmetricEncryption
|
|
|
25
25
|
});
|
|
26
26
|
});
|
|
27
27
|
}
|
|
28
|
-
|
|
28
|
+
|
|
29
29
|
public static encrypt(key: string, value: string): Promise<string>
|
|
30
30
|
{
|
|
31
31
|
return new Promise<string>((resolve, reject) =>
|
|
@@ -35,8 +35,8 @@ export class SymmetricEncryption
|
|
|
35
35
|
|
|
36
36
|
key = key.trim();
|
|
37
37
|
value = value.trim();
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
|
|
39
|
+
randomBytes(16, (err, buf) =>
|
|
40
40
|
{
|
|
41
41
|
if (err)
|
|
42
42
|
{
|
|
@@ -47,7 +47,7 @@ export class SymmetricEncryption
|
|
|
47
47
|
try
|
|
48
48
|
{
|
|
49
49
|
const iv = buf;
|
|
50
|
-
const cipher =
|
|
50
|
+
const cipher = createCipheriv("AES-256-CBC", Buffer.from(key, "hex"), iv);
|
|
51
51
|
let encrypted = cipher.update(value, "utf8", "hex");
|
|
52
52
|
encrypted += cipher.final("hex");
|
|
53
53
|
const cipherText = `${encrypted}.${iv.toString("hex")}`;
|
|
@@ -60,7 +60,7 @@ export class SymmetricEncryption
|
|
|
60
60
|
});
|
|
61
61
|
});
|
|
62
62
|
}
|
|
63
|
-
|
|
63
|
+
|
|
64
64
|
public static decrypt(key: string, value: string): string
|
|
65
65
|
{
|
|
66
66
|
given(key, "key").ensureHasValue().ensureIsString();
|
|
@@ -68,13 +68,13 @@ export class SymmetricEncryption
|
|
|
68
68
|
|
|
69
69
|
key = key.trim();
|
|
70
70
|
value = value.trim();
|
|
71
|
-
|
|
71
|
+
|
|
72
72
|
const splitted = value.split(".");
|
|
73
73
|
if (splitted.length !== 2)
|
|
74
74
|
throw new CryptoException("Invalid value.");
|
|
75
75
|
|
|
76
76
|
const iv = Buffer.from(splitted[1], "hex");
|
|
77
|
-
const deCipher =
|
|
77
|
+
const deCipher = createDecipheriv("AES-256-CBC", Buffer.from(key, "hex"), iv);
|
|
78
78
|
let decrypted = deCipher.update(splitted[0], "hex", "utf8");
|
|
79
79
|
decrypted += deCipher.final("utf8");
|
|
80
80
|
return decrypted;
|
package/src/index.ts
CHANGED
|
@@ -1,26 +1,25 @@
|
|
|
1
1
|
import "@nivinjoseph/n-ext";
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import { Hmac } from "./crypto/hmac";
|
|
5
|
-
import {
|
|
6
|
-
// import { DigitalSignature } from "./crypto/digital-signature";
|
|
7
|
-
// import { AsymmetricEncryption } from "./crypto/asymmetric-encryption";
|
|
8
|
-
import { CryptoException } from "./crypto/crypto-exception";
|
|
3
|
+
import { Hash } from "./crypto/hash.js";
|
|
4
|
+
import { Hmac } from "./crypto/hmac.js";
|
|
5
|
+
import { SymmetricEncryption } from "./crypto/symmetric-encryption.js";
|
|
6
|
+
// import { DigitalSignature } from "./crypto/digital-signature.js";
|
|
7
|
+
// import { AsymmetricEncryption } from "./crypto/asymmetric-encryption.js";
|
|
8
|
+
import { CryptoException } from "./crypto/crypto-exception.js";
|
|
9
9
|
|
|
10
|
-
import { AlgType } from "./api-security/alg-type";
|
|
11
|
-
import { Claim } from "./api-security/claim";
|
|
12
|
-
import { ClaimsIdentity } from "./api-security/claims-identity";
|
|
13
|
-
import { ExpiredTokenException } from "./api-security/expired-token-exception";
|
|
14
|
-
import { InvalidTokenException } from "./api-security/invalid-token-exception";
|
|
15
|
-
import { JsonWebToken } from "./api-security/json-web-token";
|
|
16
|
-
import { SecurityToken } from "./api-security/security-token";
|
|
10
|
+
import { AlgType } from "./api-security/alg-type.js";
|
|
11
|
+
import { Claim } from "./api-security/claim.js";
|
|
12
|
+
import { ClaimsIdentity } from "./api-security/claims-identity.js";
|
|
13
|
+
import { ExpiredTokenException } from "./api-security/expired-token-exception.js";
|
|
14
|
+
import { InvalidTokenException } from "./api-security/invalid-token-exception.js";
|
|
15
|
+
import { JsonWebToken } from "./api-security/json-web-token.js";
|
|
16
|
+
import { SecurityToken } from "./api-security/security-token.js";
|
|
17
17
|
|
|
18
18
|
|
|
19
19
|
export
|
|
20
20
|
{
|
|
21
|
-
|
|
21
|
+
|
|
22
|
+
AlgType, Claim, ClaimsIdentity,
|
|
22
23
|
// DigitalSignature, AsymmetricEncryption,
|
|
23
|
-
CryptoException,
|
|
24
|
-
|
|
25
|
-
AlgType, Claim, ClaimsIdentity, ExpiredTokenException, InvalidTokenException, JsonWebToken, SecurityToken
|
|
26
|
-
};
|
|
24
|
+
CryptoException, ExpiredTokenException, Hash, Hmac, InvalidTokenException, JsonWebToken, SecurityToken, SymmetricEncryption
|
|
25
|
+
};
|
|
@@ -3,24 +3,24 @@
|
|
|
3
3
|
// // import { CryptoException } from "./../src/crypto-exception";
|
|
4
4
|
// import "@nivinjoseph/n-ext";
|
|
5
5
|
|
|
6
|
-
//
|
|
6
|
+
// await describe("AsymmetricEncryption", () =>
|
|
7
7
|
// {
|
|
8
|
-
//
|
|
8
|
+
// await describe("generateKeyPair", () =>
|
|
9
9
|
// {
|
|
10
|
-
// test("should return string value that is not null, empty or whitespace", async () =>
|
|
10
|
+
// await test("should return string value that is not null, empty or whitespace", async () =>
|
|
11
11
|
// {
|
|
12
12
|
// let keyPair = await AsymmetricEncryption.generateKeyPair();
|
|
13
13
|
// Assert.ok(keyPair !== null && !keyPair.isEmptyOrWhiteSpace());
|
|
14
14
|
// });
|
|
15
15
|
|
|
16
|
-
// test("consecutive invocations must generate different values", async () =>
|
|
16
|
+
// await test("consecutive invocations must generate different values", async () =>
|
|
17
17
|
// {
|
|
18
18
|
// let keyPair1 = await AsymmetricEncryption.generateKeyPair();
|
|
19
19
|
// let keyPair2 = await AsymmetricEncryption.generateKeyPair();
|
|
20
20
|
// Assert.notStrictEqual(keyPair1, keyPair2);
|
|
21
21
|
// });
|
|
22
22
|
|
|
23
|
-
// // test("generate 3 KeyPairs", async () =>
|
|
23
|
+
// // await test("generate 3 KeyPairs", async () =>
|
|
24
24
|
// // {
|
|
25
25
|
// // let keyPair1 = await AsymmetricEncryption.generateKeyPair();
|
|
26
26
|
// // let keyPair2 = await AsymmetricEncryption.generateKeyPair();
|
|
@@ -34,9 +34,9 @@
|
|
|
34
34
|
// // });
|
|
35
35
|
// });
|
|
36
36
|
|
|
37
|
-
//
|
|
37
|
+
// await describe("getPublicKey", () =>
|
|
38
38
|
// {
|
|
39
|
-
// test("should return a string value that is not null, empty, whitespace or same as the input when called with a valid keypair", async () =>
|
|
39
|
+
// await test("should return a string value that is not null, empty, whitespace or same as the input when called with a valid keypair", async () =>
|
|
40
40
|
// {
|
|
41
41
|
// let keyPair = await AsymmetricEncryption.generateKeyPair();
|
|
42
42
|
// let publicKey = await AsymmetricEncryption.getPublicKey(keyPair);
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
// Assert.notStrictEqual(keyPair, publicKey);
|
|
45
45
|
// });
|
|
46
46
|
|
|
47
|
-
// test("multiple invocations should return the same value for the same keypair", async () =>
|
|
47
|
+
// await test("multiple invocations should return the same value for the same keypair", async () =>
|
|
48
48
|
// {
|
|
49
49
|
// let keyPair = await AsymmetricEncryption.generateKeyPair();
|
|
50
50
|
// let publicKey1 = await AsymmetricEncryption.getPublicKey(keyPair);
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
// Assert.strictEqual(publicKey1, publicKey2);
|
|
53
53
|
// });
|
|
54
54
|
|
|
55
|
-
// test("should return different values for different keypairs", async () =>
|
|
55
|
+
// await test("should return different values for different keypairs", async () =>
|
|
56
56
|
// {
|
|
57
57
|
// let keyPair1 = await AsymmetricEncryption.generateKeyPair();
|
|
58
58
|
// let publicKey1 = await AsymmetricEncryption.getPublicKey(keyPair1);
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
// Assert.notStrictEqual(publicKey1, publicKey2);
|
|
64
64
|
// });
|
|
65
65
|
|
|
66
|
-
// // test("get 2 public keys with same key pair", async () =>
|
|
66
|
+
// // await test("get 2 public keys with same key pair", async () =>
|
|
67
67
|
// // {
|
|
68
68
|
// // let keyPair = await AsymmetricEncryption.generateKeyPair();
|
|
69
69
|
// // let publicKey1 = await AsymmetricEncryption.getPublicKey(keyPair);
|
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
// // Assert.strictEqual(publicKey1, publicKey2);
|
|
76
76
|
// // });
|
|
77
77
|
|
|
78
|
-
// // test("throws CryptoException when key pair is null", async () =>
|
|
78
|
+
// // await test("throws CryptoException when key pair is null", async () =>
|
|
79
79
|
// // {
|
|
80
80
|
// // try
|
|
81
81
|
// // {
|
|
@@ -90,7 +90,7 @@
|
|
|
90
90
|
// // Assert.ok(false);
|
|
91
91
|
// // });
|
|
92
92
|
|
|
93
|
-
// // test("throws CryptoException when key pair is undefined", async () =>
|
|
93
|
+
// // await test("throws CryptoException when key pair is undefined", async () =>
|
|
94
94
|
// // {
|
|
95
95
|
// // try
|
|
96
96
|
// // {
|
|
@@ -105,7 +105,7 @@
|
|
|
105
105
|
// // Assert.ok(false);
|
|
106
106
|
// // });
|
|
107
107
|
|
|
108
|
-
// // test("throws CryptoException when key pair is empty String", async () =>
|
|
108
|
+
// // await test("throws CryptoException when key pair is empty String", async () =>
|
|
109
109
|
// // {
|
|
110
110
|
// // try
|
|
111
111
|
// // {
|
|
@@ -121,9 +121,9 @@
|
|
|
121
121
|
// // });
|
|
122
122
|
// });
|
|
123
123
|
|
|
124
|
-
//
|
|
124
|
+
// await describe("encrypt", () =>
|
|
125
125
|
// {
|
|
126
|
-
// test("should return cipher text when called with a keypair and plain text value", async () =>
|
|
126
|
+
// await test("should return cipher text when called with a keypair and plain text value", async () =>
|
|
127
127
|
// {
|
|
128
128
|
// let keyPair = await AsymmetricEncryption.generateKeyPair();
|
|
129
129
|
// let value = "password";
|
|
@@ -133,7 +133,7 @@
|
|
|
133
133
|
// Assert.notStrictEqual(encrypted, keyPair);
|
|
134
134
|
// });
|
|
135
135
|
|
|
136
|
-
// test("should return cipher text when called with a public key and plain text value", async () =>
|
|
136
|
+
// await test("should return cipher text when called with a public key and plain text value", async () =>
|
|
137
137
|
// {
|
|
138
138
|
// let keyPair = await AsymmetricEncryption.generateKeyPair();
|
|
139
139
|
// let publicKey = await AsymmetricEncryption.getPublicKey(keyPair);
|
|
@@ -144,7 +144,7 @@
|
|
|
144
144
|
// Assert.notStrictEqual(encrypted, keyPair);
|
|
145
145
|
// });
|
|
146
146
|
|
|
147
|
-
// // test("encrypt a string with public Key", async () =>
|
|
147
|
+
// // await test("encrypt a string with public Key", async () =>
|
|
148
148
|
// // {
|
|
149
149
|
// // let keyPair = await AsymmetricEncryption.generateKeyPair();
|
|
150
150
|
// // let publicKey = await AsymmetricEncryption.getPublicKey(keyPair);
|
|
@@ -153,7 +153,7 @@
|
|
|
153
153
|
// // Assert.notStrictEqual(encrypt, "password");
|
|
154
154
|
// // });
|
|
155
155
|
|
|
156
|
-
// // test("encrypt twice using the same key pair", async () =>
|
|
156
|
+
// // await test("encrypt twice using the same key pair", async () =>
|
|
157
157
|
// // {
|
|
158
158
|
// // let keyPair = await AsymmetricEncryption.generateKeyPair();
|
|
159
159
|
// // let encrypt1 = await AsymmetricEncryption.encrypt(keyPair, "password");
|
|
@@ -165,7 +165,7 @@
|
|
|
165
165
|
// // Assert.strictEqual(encrypt2, encrypt1);
|
|
166
166
|
// // });
|
|
167
167
|
|
|
168
|
-
// // test("encrypt 2 strings using the same key pair", async () =>
|
|
168
|
+
// // await test("encrypt 2 strings using the same key pair", async () =>
|
|
169
169
|
// // {
|
|
170
170
|
// // let keyPair = await AsymmetricEncryption.generateKeyPair();
|
|
171
171
|
// // let encrypt1 = await AsymmetricEncryption.encrypt(keyPair, "hello world");
|
|
@@ -177,7 +177,7 @@
|
|
|
177
177
|
// // Assert.notStrictEqual(encrypt2, encrypt1);
|
|
178
178
|
// // });
|
|
179
179
|
|
|
180
|
-
// // test("throws CryptoException when key pair is null", async () =>
|
|
180
|
+
// // await test("throws CryptoException when key pair is null", async () =>
|
|
181
181
|
// // {
|
|
182
182
|
// // try
|
|
183
183
|
// // {
|
|
@@ -192,7 +192,7 @@
|
|
|
192
192
|
// // Assert.ok(false);
|
|
193
193
|
// // });
|
|
194
194
|
|
|
195
|
-
// // test("throws CryptoException when key pair is undefined", async () =>
|
|
195
|
+
// // await test("throws CryptoException when key pair is undefined", async () =>
|
|
196
196
|
// // {
|
|
197
197
|
// // try
|
|
198
198
|
// // {
|
|
@@ -207,7 +207,7 @@
|
|
|
207
207
|
// // Assert.ok(false);
|
|
208
208
|
// // });
|
|
209
209
|
|
|
210
|
-
// // test("throws CryptoException when key pair is empty string", async () =>
|
|
210
|
+
// // await test("throws CryptoException when key pair is empty string", async () =>
|
|
211
211
|
// // {
|
|
212
212
|
// // try
|
|
213
213
|
// // {
|
|
@@ -222,7 +222,7 @@
|
|
|
222
222
|
// // Assert.ok(false);
|
|
223
223
|
// // });
|
|
224
224
|
|
|
225
|
-
// // test("throws CryptoException when key pair is empty string", async () =>
|
|
225
|
+
// // await test("throws CryptoException when key pair is empty string", async () =>
|
|
226
226
|
// // {
|
|
227
227
|
// // try
|
|
228
228
|
// // {
|
|
@@ -238,7 +238,7 @@
|
|
|
238
238
|
// // Assert.ok(false);
|
|
239
239
|
// // });
|
|
240
240
|
|
|
241
|
-
// // test("throws CryptoException when key pair and value are empty strings", async () =>
|
|
241
|
+
// // await test("throws CryptoException when key pair and value are empty strings", async () =>
|
|
242
242
|
// // {
|
|
243
243
|
// // try
|
|
244
244
|
// // {
|
|
@@ -253,7 +253,7 @@
|
|
|
253
253
|
// // Assert.ok(false);
|
|
254
254
|
// // });
|
|
255
255
|
|
|
256
|
-
// // test("encrypt using public key and key pair", async () =>
|
|
256
|
+
// // await test("encrypt using public key and key pair", async () =>
|
|
257
257
|
// // {
|
|
258
258
|
// // let keyPair = await AsymmetricEncryption.generateKeyPair();
|
|
259
259
|
// // let encrypt1 = await AsymmetricEncryption.encrypt(keyPair, "hello world");
|
|
@@ -267,9 +267,9 @@
|
|
|
267
267
|
// // });
|
|
268
268
|
// });
|
|
269
269
|
|
|
270
|
-
//
|
|
270
|
+
// await describe("decrypt", () =>
|
|
271
271
|
// {
|
|
272
|
-
// test("should return plain text when called with key pair and cipher text encrypted with key pair", async () =>
|
|
272
|
+
// await test("should return plain text when called with key pair and cipher text encrypted with key pair", async () =>
|
|
273
273
|
// {
|
|
274
274
|
// let keyPair = await AsymmetricEncryption.generateKeyPair();
|
|
275
275
|
// let value = "password";
|
|
@@ -278,7 +278,7 @@
|
|
|
278
278
|
// Assert.strictEqual(decrypted, value);
|
|
279
279
|
// });
|
|
280
280
|
|
|
281
|
-
// test("should return plain text when called with key pair and cipher text encrypted with public key of key pair", async () =>
|
|
281
|
+
// await test("should return plain text when called with key pair and cipher text encrypted with public key of key pair", async () =>
|
|
282
282
|
// {
|
|
283
283
|
// let keyPair = await AsymmetricEncryption.generateKeyPair();
|
|
284
284
|
// let publicKey = await AsymmetricEncryption.getPublicKey(keyPair);
|
|
@@ -290,7 +290,7 @@
|
|
|
290
290
|
|
|
291
291
|
|
|
292
292
|
|
|
293
|
-
// // test("decrypt using public key when encrypted by key pair", async () =>
|
|
293
|
+
// // await test("decrypt using public key when encrypted by key pair", async () =>
|
|
294
294
|
// // {
|
|
295
295
|
// // let keyPair = await AsymmetricEncryption.generateKeyPair();
|
|
296
296
|
// // let publicKey = await AsymmetricEncryption.getPublicKey(keyPair);
|
|
@@ -300,7 +300,7 @@
|
|
|
300
300
|
// // Assert.strictEqual(decrypt, "password");
|
|
301
301
|
// // });
|
|
302
302
|
|
|
303
|
-
// // test("decrypt using key pair when encrypted by public key", async () =>
|
|
303
|
+
// // await test("decrypt using key pair when encrypted by public key", async () =>
|
|
304
304
|
// // {
|
|
305
305
|
// // let keyPair = await AsymmetricEncryption.generateKeyPair();
|
|
306
306
|
// // let publicKey = await AsymmetricEncryption.getPublicKey(keyPair);
|
|
@@ -310,7 +310,7 @@
|
|
|
310
310
|
// // Assert.strictEqual(decrypt, "password");
|
|
311
311
|
// // });
|
|
312
312
|
|
|
313
|
-
// // test("decrypt using key pair when encrypted by key pair", async () =>
|
|
313
|
+
// // await test("decrypt using key pair when encrypted by key pair", async () =>
|
|
314
314
|
// // {
|
|
315
315
|
// // let keyPair = await AsymmetricEncryption.generateKeyPair();
|
|
316
316
|
// // let encrypt = await AsymmetricEncryption.encrypt(keyPair, "password");
|
|
@@ -318,7 +318,7 @@
|
|
|
318
318
|
// // Assert.notStrictEqual(decrypt, "password");
|
|
319
319
|
// // });
|
|
320
320
|
|
|
321
|
-
// // test("decrypt using public key when encrypted by public key", async () =>
|
|
321
|
+
// // await test("decrypt using public key when encrypted by public key", async () =>
|
|
322
322
|
// // {
|
|
323
323
|
// // let keyPair = await AsymmetricEncryption.generateKeyPair();
|
|
324
324
|
// // let publicKey = await AsymmetricEncryption.getPublicKey(keyPair);
|
|
@@ -327,7 +327,7 @@
|
|
|
327
327
|
// // Assert.notStrictEqual(decrypt, "password");
|
|
328
328
|
// // });
|
|
329
329
|
|
|
330
|
-
// // test("throws CryptoException when key is null", async () =>
|
|
330
|
+
// // await test("throws CryptoException when key is null", async () =>
|
|
331
331
|
// // {
|
|
332
332
|
// // let keyPair = await AsymmetricEncryption.generateKeyPair();
|
|
333
333
|
// // let encrypt = await AsymmetricEncryption.encrypt(keyPair, "password");
|
|
@@ -344,7 +344,7 @@
|
|
|
344
344
|
// // Assert.ok(false);
|
|
345
345
|
// // });
|
|
346
346
|
|
|
347
|
-
// // test("throws CryptoException when key is undefined", async () =>
|
|
347
|
+
// // await test("throws CryptoException when key is undefined", async () =>
|
|
348
348
|
// // {
|
|
349
349
|
// // let keyPair = await AsymmetricEncryption.generateKeyPair();
|
|
350
350
|
// // let encrypt = await AsymmetricEncryption.encrypt(keyPair, "password");
|
|
@@ -361,7 +361,7 @@
|
|
|
361
361
|
// // Assert.ok(false);
|
|
362
362
|
// // });
|
|
363
363
|
|
|
364
|
-
// // test("throws CryptoException when value is null", async () =>
|
|
364
|
+
// // await test("throws CryptoException when value is null", async () =>
|
|
365
365
|
// // {
|
|
366
366
|
// // let keyPair = await AsymmetricEncryption.generateKeyPair();
|
|
367
367
|
// // let publicKey = await AsymmetricEncryption.getPublicKey(keyPair);
|
|
@@ -378,7 +378,7 @@
|
|
|
378
378
|
// // Assert.ok(false);
|
|
379
379
|
// // });
|
|
380
380
|
|
|
381
|
-
// // test("throws CryptoException when value is undefined", async () =>
|
|
381
|
+
// // await test("throws CryptoException when value is undefined", async () =>
|
|
382
382
|
// // {
|
|
383
383
|
// // let keyPair = await AsymmetricEncryption.generateKeyPair();
|
|
384
384
|
// // let publicKey = await AsymmetricEncryption.getPublicKey(keyPair);
|
|
@@ -395,7 +395,7 @@
|
|
|
395
395
|
// // Assert.ok(false);
|
|
396
396
|
// // });
|
|
397
397
|
|
|
398
|
-
// // test("throws CryptoException when key and value is null", async () =>
|
|
398
|
+
// // await test("throws CryptoException when key and value is null", async () =>
|
|
399
399
|
// // {
|
|
400
400
|
// // try
|
|
401
401
|
// // {
|