@nivinjoseph/n-sec 5.0.5 → 6.0.1
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/.eslintrc +13 -4
- package/.vscode/settings.json +103 -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 +15 -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/package.json +23 -24
- package/src/api-security/claims-identity.ts +1 -1
- package/src/api-security/json-web-token.ts +21 -21
- package/src/bin.ts +1 -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
|
@@ -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
|
// // {
|
|
@@ -4,11 +4,11 @@
|
|
|
4
4
|
// import "@nivinjoseph/n-ext";
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
//
|
|
7
|
+
// await describe("digitalSignature", () =>
|
|
8
8
|
// {
|
|
9
|
-
//
|
|
9
|
+
// await describe("sign", () =>
|
|
10
10
|
// {
|
|
11
|
-
// test("should return string value thats is not null, empty, whitespace, same as value or key pair when invoked with key pair and value", async () =>
|
|
11
|
+
// await test("should return string value thats is not null, empty, whitespace, same as value or key pair when invoked with key pair and value", async () =>
|
|
12
12
|
// {
|
|
13
13
|
// let keyPair = await AsymmetricEncryption.generateKeyPair();
|
|
14
14
|
// let value = "some value";
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
// });
|
|
20
20
|
|
|
21
21
|
|
|
22
|
-
// // test("should throw CryptoException when KeyPair is null", async () =>
|
|
22
|
+
// // await test("should throw CryptoException when KeyPair is null", async () =>
|
|
23
23
|
// // {
|
|
24
24
|
// // try
|
|
25
25
|
// // {
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
// // assert.ok(false);
|
|
35
35
|
// // });
|
|
36
36
|
|
|
37
|
-
// // test("should throw CryptoException when KeyPair is undefined", async () =>
|
|
37
|
+
// // await test("should throw CryptoException when KeyPair is undefined", async () =>
|
|
38
38
|
// // {
|
|
39
39
|
// // try
|
|
40
40
|
// // {
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
// // assert.ok(false);
|
|
50
50
|
// // });
|
|
51
51
|
|
|
52
|
-
// // test("should throw CryptoException when value is null", async () =>
|
|
52
|
+
// // await test("should throw CryptoException when value is null", async () =>
|
|
53
53
|
// // {
|
|
54
54
|
// // let keyPair = await AsymmetricEncryption.generateKeyPair();
|
|
55
55
|
// // try
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
// // assert.ok(false);
|
|
66
66
|
// // });
|
|
67
67
|
|
|
68
|
-
// // test("should throw CryptoException when value is undefined", async () =>
|
|
68
|
+
// // await test("should throw CryptoException when value is undefined", async () =>
|
|
69
69
|
// // {
|
|
70
70
|
// // let keyPair = await AsymmetricEncryption.generateKeyPair();
|
|
71
71
|
// // try
|
|
@@ -81,7 +81,7 @@
|
|
|
81
81
|
// // assert.ok(false);
|
|
82
82
|
// // });
|
|
83
83
|
|
|
84
|
-
// // test("should throw CryptoException when value is empty string", async () =>
|
|
84
|
+
// // await test("should throw CryptoException when value is empty string", async () =>
|
|
85
85
|
// // {
|
|
86
86
|
// // let keyPair = await AsymmetricEncryption.generateKeyPair();
|
|
87
87
|
// // try
|
|
@@ -97,7 +97,7 @@
|
|
|
97
97
|
// // assert.ok(false);
|
|
98
98
|
// // });
|
|
99
99
|
|
|
100
|
-
// // test("should throw CryptoException when keyPair is empty string", async () =>
|
|
100
|
+
// // await test("should throw CryptoException when keyPair is empty string", async () =>
|
|
101
101
|
// // {
|
|
102
102
|
// // try
|
|
103
103
|
// // {
|
|
@@ -113,9 +113,9 @@
|
|
|
113
113
|
// // });
|
|
114
114
|
// });
|
|
115
115
|
|
|
116
|
-
//
|
|
116
|
+
// await describe("verify", () =>
|
|
117
117
|
// {
|
|
118
|
-
// test("should return true when called with public key of key pair, value and signature of value generated using key pair", async () =>
|
|
118
|
+
// await test("should return true when called with public key of key pair, value and signature of value generated using key pair", async () =>
|
|
119
119
|
// {
|
|
120
120
|
// let keyPair = await AsymmetricEncryption.generateKeyPair();
|
|
121
121
|
// let publicKey = await AsymmetricEncryption.getPublicKey(keyPair);
|
|
@@ -125,7 +125,7 @@
|
|
|
125
125
|
// Assert.strictEqual(verification, true);
|
|
126
126
|
// });
|
|
127
127
|
|
|
128
|
-
// test("should return false when called with unrelated public key, value and signature", async () =>
|
|
128
|
+
// await test("should return false when called with unrelated public key, value and signature", async () =>
|
|
129
129
|
// {
|
|
130
130
|
// let keyPair1 = await AsymmetricEncryption.generateKeyPair();
|
|
131
131
|
// let keyPair2 = await AsymmetricEncryption.generateKeyPair();
|
|
@@ -136,7 +136,7 @@
|
|
|
136
136
|
// Assert.strictEqual(verification, false);
|
|
137
137
|
// });
|
|
138
138
|
|
|
139
|
-
// test("should return false when called with tampered value", async () =>
|
|
139
|
+
// await test("should return false when called with tampered value", async () =>
|
|
140
140
|
// {
|
|
141
141
|
// let keyPair = await AsymmetricEncryption.generateKeyPair();
|
|
142
142
|
// let publicKey = await AsymmetricEncryption.getPublicKey(keyPair);
|
|
@@ -147,7 +147,7 @@
|
|
|
147
147
|
// Assert.strictEqual(verification, false);
|
|
148
148
|
// });
|
|
149
149
|
|
|
150
|
-
// test("should return false when called with a tampered signature", async () =>
|
|
150
|
+
// await test("should return false when called with a tampered signature", async () =>
|
|
151
151
|
// {
|
|
152
152
|
// let keyPair = await AsymmetricEncryption.generateKeyPair();
|
|
153
153
|
// let publicKey = await AsymmetricEncryption.getPublicKey(keyPair);
|
|
@@ -160,7 +160,7 @@
|
|
|
160
160
|
|
|
161
161
|
|
|
162
162
|
|
|
163
|
-
// // test("successfully verify the signed", async () =>
|
|
163
|
+
// // await test("successfully verify the signed", async () =>
|
|
164
164
|
// // {
|
|
165
165
|
// // let keyPair = await AsymmetricEncryption.generateKeyPair();
|
|
166
166
|
// // let publicKey = await AsymmetricEncryption.getPublicKey(keyPair);
|
|
@@ -169,7 +169,7 @@
|
|
|
169
169
|
// // Assert.ok(verify);
|
|
170
170
|
// // });
|
|
171
171
|
|
|
172
|
-
// // test("un-verify modified signature", async () =>
|
|
172
|
+
// // await test("un-verify modified signature", async () =>
|
|
173
173
|
// // {
|
|
174
174
|
// // let keyPair = await AsymmetricEncryption.generateKeyPair();
|
|
175
175
|
// // let publicKey = await AsymmetricEncryption.getPublicKey(keyPair);
|
|
@@ -179,7 +179,7 @@
|
|
|
179
179
|
// // Assert.ok(!verify);
|
|
180
180
|
// // });
|
|
181
181
|
|
|
182
|
-
// // test("un-verify when wrong public key is given", async () =>
|
|
182
|
+
// // await test("un-verify when wrong public key is given", async () =>
|
|
183
183
|
// // {
|
|
184
184
|
// // let keyPair = await AsymmetricEncryption.generateKeyPair();
|
|
185
185
|
// // let signature = await DigitalSignature.sign(keyPair, "some-string");
|
|
@@ -189,7 +189,7 @@
|
|
|
189
189
|
// // Assert.ok(!verify);
|
|
190
190
|
// // });
|
|
191
191
|
|
|
192
|
-
// // test("should throw CryptoException when public key is null", async () =>
|
|
192
|
+
// // await test("should throw CryptoException when public key is null", async () =>
|
|
193
193
|
// // {
|
|
194
194
|
// // let keyPair = await AsymmetricEncryption.generateKeyPair();
|
|
195
195
|
// // let signature = await DigitalSignature.sign(keyPair, "some-string");
|
|
@@ -206,7 +206,7 @@
|
|
|
206
206
|
// // Assert.ok(false);
|
|
207
207
|
// // });
|
|
208
208
|
|
|
209
|
-
// // test("should throw CryptoException when value is null", async () =>
|
|
209
|
+
// // await test("should throw CryptoException when value is null", async () =>
|
|
210
210
|
// // {
|
|
211
211
|
// // let keyPair = await AsymmetricEncryption.generateKeyPair();
|
|
212
212
|
// // let signature = await DigitalSignature.sign(keyPair, "some-string");
|
|
@@ -224,7 +224,7 @@
|
|
|
224
224
|
// // Assert.ok(false);
|
|
225
225
|
// // });
|
|
226
226
|
|
|
227
|
-
// // test("should throw CryptoException when value is empty string", async () =>
|
|
227
|
+
// // await test("should throw CryptoException when value is empty string", async () =>
|
|
228
228
|
// // {
|
|
229
229
|
// // let keyPair = await AsymmetricEncryption.generateKeyPair();
|
|
230
230
|
// // let signature = await DigitalSignature.sign(keyPair, "some-string");
|
|
@@ -242,7 +242,7 @@
|
|
|
242
242
|
// // Assert.ok(false);
|
|
243
243
|
// // });
|
|
244
244
|
|
|
245
|
-
// // test("should throw CryptoException when signature is null", async () =>
|
|
245
|
+
// // await test("should throw CryptoException when signature is null", async () =>
|
|
246
246
|
// // {
|
|
247
247
|
// // let keyPair = await AsymmetricEncryption.generateKeyPair();
|
|
248
248
|
// // let publicKey = await AsymmetricEncryption.getPublicKey(keyPair);
|
|
@@ -259,7 +259,7 @@
|
|
|
259
259
|
// // Assert.ok(false);
|
|
260
260
|
// // });
|
|
261
261
|
|
|
262
|
-
// // test("should throw CryptoException when value, key pair and signature are all null", async () =>
|
|
262
|
+
// // await test("should throw CryptoException when value, key pair and signature are all null", async () =>
|
|
263
263
|
// // {
|
|
264
264
|
// // try
|
|
265
265
|
// // {
|