@enbox/crypto 0.0.2 → 0.0.4
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/README.md +34 -102
- package/dist/browser.mjs +6 -10
- package/dist/browser.mjs.map +4 -4
- package/dist/esm/algorithms/aes-ctr.js +1 -1
- package/dist/esm/algorithms/aes-gcm.js +35 -2
- package/dist/esm/algorithms/aes-gcm.js.map +1 -1
- package/dist/esm/algorithms/aes-kw.js +154 -0
- package/dist/esm/algorithms/aes-kw.js.map +1 -0
- package/dist/esm/algorithms/ecdsa.js +119 -6
- package/dist/esm/algorithms/ecdsa.js.map +1 -1
- package/dist/esm/algorithms/eddsa.js +99 -6
- package/dist/esm/algorithms/eddsa.js.map +1 -1
- package/dist/esm/algorithms/hkdf.js +53 -0
- package/dist/esm/algorithms/hkdf.js.map +1 -0
- package/dist/esm/algorithms/pbkdf2.js +55 -0
- package/dist/esm/algorithms/pbkdf2.js.map +1 -0
- package/dist/esm/algorithms/sha-2.js +2 -2
- package/dist/esm/algorithms/sha-2.js.map +1 -1
- package/dist/esm/algorithms/x25519.js +125 -0
- package/dist/esm/algorithms/x25519.js.map +1 -0
- package/dist/esm/crypto-error.js +41 -0
- package/dist/esm/crypto-error.js.map +1 -0
- package/dist/esm/index.js +8 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/jose/jwk.js +52 -26
- package/dist/esm/jose/jwk.js.map +1 -1
- package/dist/esm/local-key-manager.js +9 -3
- package/dist/esm/local-key-manager.js.map +1 -1
- package/dist/esm/primitives/aes-ctr.js.map +1 -1
- package/dist/esm/primitives/aes-gcm.js.map +1 -1
- package/dist/esm/primitives/aes-kw.js +246 -0
- package/dist/esm/primitives/aes-kw.js.map +1 -0
- package/dist/esm/primitives/concat-kdf.js +1 -1
- package/dist/esm/primitives/concat-kdf.js.map +1 -1
- package/dist/esm/primitives/ecies-secp256k1.js +79 -0
- package/dist/esm/primitives/ecies-secp256k1.js.map +1 -0
- package/dist/esm/primitives/ed25519.js +3 -3
- package/dist/esm/primitives/ed25519.js.map +1 -1
- package/dist/esm/primitives/hkdf.js +79 -0
- package/dist/esm/primitives/hkdf.js.map +1 -0
- package/dist/esm/primitives/pbkdf2.js +49 -0
- package/dist/esm/primitives/pbkdf2.js.map +1 -1
- package/dist/esm/primitives/secp256k1.js +4 -4
- package/dist/esm/primitives/secp256k1.js.map +1 -1
- package/dist/esm/primitives/secp256r1.js +4 -4
- package/dist/esm/primitives/secp256r1.js.map +1 -1
- package/dist/esm/primitives/x25519.js +10 -17
- package/dist/esm/primitives/x25519.js.map +1 -1
- package/dist/esm/primitives/xchacha20-poly1305.js +48 -3
- package/dist/esm/primitives/xchacha20-poly1305.js.map +1 -1
- package/dist/esm/primitives/xchacha20.js +1 -1
- package/dist/esm/primitives/xchacha20.js.map +1 -1
- package/dist/esm/utils.js +30 -0
- package/dist/esm/utils.js.map +1 -1
- package/dist/types/algorithms/aes-ctr.d.ts +2 -2
- package/dist/types/algorithms/aes-ctr.d.ts.map +1 -1
- package/dist/types/algorithms/aes-gcm.d.ts +25 -5
- package/dist/types/algorithms/aes-gcm.d.ts.map +1 -1
- package/dist/types/algorithms/aes-kw.d.ts +129 -0
- package/dist/types/algorithms/aes-kw.d.ts.map +1 -0
- package/dist/types/algorithms/ecdsa.d.ts +49 -4
- package/dist/types/algorithms/ecdsa.d.ts.map +1 -1
- package/dist/types/algorithms/eddsa.d.ts +49 -4
- package/dist/types/algorithms/eddsa.d.ts.map +1 -1
- package/dist/types/algorithms/hkdf.d.ts +35 -0
- package/dist/types/algorithms/hkdf.d.ts.map +1 -0
- package/dist/types/algorithms/pbkdf2.d.ts +35 -0
- package/dist/types/algorithms/pbkdf2.d.ts.map +1 -0
- package/dist/types/algorithms/sha-2.d.ts +2 -2
- package/dist/types/algorithms/sha-2.d.ts.map +1 -1
- package/dist/types/algorithms/x25519.d.ts +76 -0
- package/dist/types/algorithms/x25519.d.ts.map +1 -0
- package/dist/types/crypto-error.d.ts +29 -0
- package/dist/types/crypto-error.d.ts.map +1 -0
- package/dist/types/index.d.ts +8 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/jose/jwk.d.ts.map +1 -1
- package/dist/types/local-key-manager.d.ts +6 -6
- package/dist/types/local-key-manager.d.ts.map +1 -1
- package/dist/types/primitives/aes-kw.d.ts +103 -0
- package/dist/types/primitives/aes-kw.d.ts.map +1 -0
- package/dist/types/primitives/concat-kdf.d.ts +1 -1
- package/dist/types/primitives/concat-kdf.d.ts.map +1 -1
- package/dist/types/primitives/ecies-secp256k1.d.ts +53 -0
- package/dist/types/primitives/ecies-secp256k1.d.ts.map +1 -0
- package/dist/types/primitives/hkdf.d.ts +90 -0
- package/dist/types/primitives/hkdf.d.ts.map +1 -0
- package/dist/types/primitives/pbkdf2.d.ts +58 -0
- package/dist/types/primitives/pbkdf2.d.ts.map +1 -1
- package/dist/types/primitives/x25519.d.ts +9 -16
- package/dist/types/primitives/x25519.d.ts.map +1 -1
- package/dist/types/primitives/xchacha20-poly1305.d.ts +47 -0
- package/dist/types/primitives/xchacha20-poly1305.d.ts.map +1 -1
- package/dist/types/types/cipher.d.ts +1 -1
- package/dist/types/types/crypto-api.d.ts +54 -6
- package/dist/types/types/crypto-api.d.ts.map +1 -1
- package/dist/types/types/key-converter.d.ts +37 -15
- package/dist/types/types/key-converter.d.ts.map +1 -1
- package/dist/types/types/key-deriver.d.ts +41 -0
- package/dist/types/types/key-deriver.d.ts.map +1 -1
- package/dist/types/types/key-io.d.ts +37 -0
- package/dist/types/types/key-io.d.ts.map +1 -1
- package/dist/types/types/params-direct.d.ts +96 -1
- package/dist/types/types/params-direct.d.ts.map +1 -1
- package/dist/types/types/params-kms.d.ts +55 -0
- package/dist/types/types/params-kms.d.ts.map +1 -1
- package/dist/types/utils.d.ts +19 -0
- package/dist/types/utils.d.ts.map +1 -1
- package/dist/utils.js +1 -1
- package/dist/utils.js.map +4 -4
- package/package.json +29 -45
- package/src/algorithms/aes-ctr.ts +2 -2
- package/src/algorithms/aes-gcm.ts +41 -4
- package/src/algorithms/aes-kw.ts +182 -0
- package/src/algorithms/ecdsa.ts +145 -8
- package/src/algorithms/eddsa.ts +117 -10
- package/src/algorithms/hkdf.ts +54 -0
- package/src/algorithms/pbkdf2.ts +57 -0
- package/src/algorithms/sha-2.ts +3 -3
- package/src/algorithms/x25519.ts +153 -0
- package/src/crypto-error.ts +45 -0
- package/src/index.ts +8 -0
- package/src/jose/jwk.ts +32 -32
- package/src/local-key-manager.ts +22 -16
- package/src/primitives/aes-ctr.ts +1 -1
- package/src/primitives/aes-gcm.ts +5 -5
- package/src/primitives/aes-kw.ts +269 -0
- package/src/primitives/concat-kdf.ts +4 -2
- package/src/primitives/ecies-secp256k1.ts +113 -0
- package/src/primitives/ed25519.ts +6 -6
- package/src/primitives/hkdf.ts +121 -0
- package/src/primitives/pbkdf2.ts +91 -0
- package/src/primitives/secp256k1.ts +6 -6
- package/src/primitives/secp256r1.ts +6 -6
- package/src/primitives/x25519.ts +12 -19
- package/src/primitives/xchacha20-poly1305.ts +57 -4
- package/src/primitives/xchacha20.ts +1 -1
- package/src/types/cipher.ts +1 -1
- package/src/types/crypto-api.ts +129 -11
- package/src/types/key-converter.ts +33 -7
- package/src/types/key-deriver.ts +49 -0
- package/src/types/key-io.ts +40 -0
- package/src/types/params-direct.ts +118 -1
- package/src/types/params-kms.ts +67 -0
- package/src/utils.ts +55 -2
- package/dist/browser.js +0 -64
- package/dist/browser.js.map +0 -7
- package/dist/cjs/algorithms/aes-ctr.js +0 -188
- package/dist/cjs/algorithms/aes-ctr.js.map +0 -1
- package/dist/cjs/algorithms/aes-gcm.js +0 -196
- package/dist/cjs/algorithms/aes-gcm.js.map +0 -1
- package/dist/cjs/algorithms/crypto-algorithm.js +0 -13
- package/dist/cjs/algorithms/crypto-algorithm.js.map +0 -1
- package/dist/cjs/algorithms/ecdsa.js +0 -352
- package/dist/cjs/algorithms/ecdsa.js.map +0 -1
- package/dist/cjs/algorithms/eddsa.js +0 -325
- package/dist/cjs/algorithms/eddsa.js.map +0 -1
- package/dist/cjs/algorithms/sha-2.js +0 -119
- package/dist/cjs/algorithms/sha-2.js.map +0 -1
- package/dist/cjs/index.js +0 -41
- package/dist/cjs/index.js.map +0 -1
- package/dist/cjs/jose/jwe.js +0 -3
- package/dist/cjs/jose/jwe.js.map +0 -1
- package/dist/cjs/jose/jwk.js +0 -278
- package/dist/cjs/jose/jwk.js.map +0 -1
- package/dist/cjs/jose/jws.js +0 -3
- package/dist/cjs/jose/jws.js.map +0 -1
- package/dist/cjs/jose/jwt.js +0 -3
- package/dist/cjs/jose/jwt.js.map +0 -1
- package/dist/cjs/jose/utils.js +0 -60
- package/dist/cjs/jose/utils.js.map +0 -1
- package/dist/cjs/local-key-manager.js +0 -521
- package/dist/cjs/local-key-manager.js.map +0 -1
- package/dist/cjs/package.json +0 -1
- package/dist/cjs/primitives/aes-ctr.js +0 -398
- package/dist/cjs/primitives/aes-ctr.js.map +0 -1
- package/dist/cjs/primitives/aes-gcm.js +0 -425
- package/dist/cjs/primitives/aes-gcm.js.map +0 -1
- package/dist/cjs/primitives/concat-kdf.js +0 -215
- package/dist/cjs/primitives/concat-kdf.js.map +0 -1
- package/dist/cjs/primitives/ed25519.js +0 -651
- package/dist/cjs/primitives/ed25519.js.map +0 -1
- package/dist/cjs/primitives/pbkdf2.js +0 -120
- package/dist/cjs/primitives/pbkdf2.js.map +0 -1
- package/dist/cjs/primitives/secp256k1.js +0 -958
- package/dist/cjs/primitives/secp256k1.js.map +0 -1
- package/dist/cjs/primitives/secp256r1.js +0 -959
- package/dist/cjs/primitives/secp256r1.js.map +0 -1
- package/dist/cjs/primitives/sha256.js +0 -93
- package/dist/cjs/primitives/sha256.js.map +0 -1
- package/dist/cjs/primitives/x25519.js +0 -498
- package/dist/cjs/primitives/x25519.js.map +0 -1
- package/dist/cjs/primitives/xchacha20-poly1305.js +0 -340
- package/dist/cjs/primitives/xchacha20-poly1305.js.map +0 -1
- package/dist/cjs/primitives/xchacha20.js +0 -316
- package/dist/cjs/primitives/xchacha20.js.map +0 -1
- package/dist/cjs/types/cipher.js +0 -3
- package/dist/cjs/types/cipher.js.map +0 -1
- package/dist/cjs/types/crypto-api.js +0 -3
- package/dist/cjs/types/crypto-api.js.map +0 -1
- package/dist/cjs/types/hasher.js +0 -3
- package/dist/cjs/types/hasher.js.map +0 -1
- package/dist/cjs/types/identifier.js +0 -3
- package/dist/cjs/types/identifier.js.map +0 -1
- package/dist/cjs/types/key-compressor.js +0 -3
- package/dist/cjs/types/key-compressor.js.map +0 -1
- package/dist/cjs/types/key-converter.js +0 -3
- package/dist/cjs/types/key-converter.js.map +0 -1
- package/dist/cjs/types/key-deriver.js +0 -3
- package/dist/cjs/types/key-deriver.js.map +0 -1
- package/dist/cjs/types/key-generator.js +0 -3
- package/dist/cjs/types/key-generator.js.map +0 -1
- package/dist/cjs/types/key-io.js +0 -3
- package/dist/cjs/types/key-io.js.map +0 -1
- package/dist/cjs/types/key-wrapper.js +0 -3
- package/dist/cjs/types/key-wrapper.js.map +0 -1
- package/dist/cjs/types/params-direct.js +0 -3
- package/dist/cjs/types/params-direct.js.map +0 -1
- package/dist/cjs/types/params-enclosed.js +0 -3
- package/dist/cjs/types/params-enclosed.js.map +0 -1
- package/dist/cjs/types/params-kms.js +0 -3
- package/dist/cjs/types/params-kms.js.map +0 -1
- package/dist/cjs/types/signer.js +0 -3
- package/dist/cjs/types/signer.js.map +0 -1
- package/dist/cjs/utils.js +0 -173
- package/dist/cjs/utils.js.map +0 -1
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
-
});
|
|
25
|
-
};
|
|
26
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
27
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
28
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
29
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
30
|
-
function step(op) {
|
|
31
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
32
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
33
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
34
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
35
|
-
switch (op[0]) {
|
|
36
|
-
case 0: case 1: t = op; break;
|
|
37
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
38
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
39
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
40
|
-
default:
|
|
41
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
42
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
43
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
44
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
45
|
-
if (t[2]) _.ops.pop();
|
|
46
|
-
_.trys.pop(); continue;
|
|
47
|
-
}
|
|
48
|
-
op = body.call(thisArg, _);
|
|
49
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
50
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
|
-
exports.AesCtrAlgorithm = void 0;
|
|
55
|
-
var aes_ctr_js_1 = require("../primitives/aes-ctr.js");
|
|
56
|
-
var crypto_algorithm_js_1 = require("./crypto-algorithm.js");
|
|
57
|
-
/**
|
|
58
|
-
* The `AesCtrAlgorithm` class provides a concrete implementation for cryptographic operations using
|
|
59
|
-
* the AES algorithm in Counter (CTR) mode. This class implements both {@link Cipher | `Cipher`} and
|
|
60
|
-
* { @link KeyGenerator | `KeyGenerator`} interfaces, providing key generation, encryption, and
|
|
61
|
-
* decryption features.
|
|
62
|
-
*
|
|
63
|
-
* This class is typically accessed through implementations that extend the
|
|
64
|
-
* {@link CryptoApi | `CryptoApi`} interface.
|
|
65
|
-
*/
|
|
66
|
-
var AesCtrAlgorithm = /** @class */ (function (_super) {
|
|
67
|
-
__extends(AesCtrAlgorithm, _super);
|
|
68
|
-
function AesCtrAlgorithm() {
|
|
69
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Decrypts the provided data using AES-CTR.
|
|
73
|
-
*
|
|
74
|
-
* @remarks
|
|
75
|
-
* This method performs AES-CTR decryption on the given encrypted data using the specified key.
|
|
76
|
-
* Similar to the encryption process, it requires an initial counter block and the length
|
|
77
|
-
* of the counter block, along with the encrypted data and the decryption key. The method
|
|
78
|
-
* returns the decrypted data as a Uint8Array.
|
|
79
|
-
*
|
|
80
|
-
* @example
|
|
81
|
-
* ```ts
|
|
82
|
-
* const aesCtr = new AesCtrAlgorithm();
|
|
83
|
-
* const encryptedData = new Uint8Array([...]); // Encrypted data
|
|
84
|
-
* const counter = new Uint8Array(16); // 16-byte (128-bit) counter block used during encryption
|
|
85
|
-
* const key = { ... }; // A Jwk object representing the same AES key used for encryption
|
|
86
|
-
* const decryptedData = await aesCtr.decrypt({
|
|
87
|
-
* data: encryptedData,
|
|
88
|
-
* counter,
|
|
89
|
-
* key,
|
|
90
|
-
* length: 128 // Length of the counter in bits
|
|
91
|
-
* });
|
|
92
|
-
* ```
|
|
93
|
-
*
|
|
94
|
-
* @param params - The parameters for the decryption operation.
|
|
95
|
-
*
|
|
96
|
-
* @returns A Promise that resolves to the decrypted data as a Uint8Array.
|
|
97
|
-
*/
|
|
98
|
-
AesCtrAlgorithm.prototype.decrypt = function (params) {
|
|
99
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
100
|
-
var plaintext;
|
|
101
|
-
return __generator(this, function (_a) {
|
|
102
|
-
plaintext = aes_ctr_js_1.AesCtr.decrypt(params);
|
|
103
|
-
return [2 /*return*/, plaintext];
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
};
|
|
107
|
-
/**
|
|
108
|
-
* Encrypts the provided data using AES-CTR.
|
|
109
|
-
*
|
|
110
|
-
* @remarks
|
|
111
|
-
* This method performs AES-CTR encryption on the given data using the specified key.
|
|
112
|
-
* It requires the initial counter block and the length of the counter block, alongside
|
|
113
|
-
* the data and key. The method is designed to work asynchronously and returns the
|
|
114
|
-
* encrypted data as a Uint8Array.
|
|
115
|
-
*
|
|
116
|
-
* @example
|
|
117
|
-
* ```ts
|
|
118
|
-
* const aesCtr = new AesCtrAlgorithm();
|
|
119
|
-
* const data = new TextEncoder().encode('Messsage');
|
|
120
|
-
* const counter = new Uint8Array(16); // 16-byte (128-bit) counter block
|
|
121
|
-
* const key = { ... }; // A Jwk object representing an AES key
|
|
122
|
-
* const encryptedData = await aesCtr.encrypt({
|
|
123
|
-
* data,
|
|
124
|
-
* counter,
|
|
125
|
-
* key,
|
|
126
|
-
* length: 128 // Length of the counter in bits
|
|
127
|
-
* });
|
|
128
|
-
* ```
|
|
129
|
-
*
|
|
130
|
-
* @param params - The parameters for the encryption operation.
|
|
131
|
-
*
|
|
132
|
-
* @returns A Promise that resolves to the encrypted data as a Uint8Array.
|
|
133
|
-
*/
|
|
134
|
-
AesCtrAlgorithm.prototype.encrypt = function (params) {
|
|
135
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
136
|
-
var ciphertext;
|
|
137
|
-
return __generator(this, function (_a) {
|
|
138
|
-
ciphertext = aes_ctr_js_1.AesCtr.encrypt(params);
|
|
139
|
-
return [2 /*return*/, ciphertext];
|
|
140
|
-
});
|
|
141
|
-
});
|
|
142
|
-
};
|
|
143
|
-
/**
|
|
144
|
-
* Generates a symmetric key for AES in Counter (CTR) mode in JSON Web Key (JWK) format.
|
|
145
|
-
*
|
|
146
|
-
* @remarks
|
|
147
|
-
* This method generates a symmetric AES key for use in CTR mode, based on the specified
|
|
148
|
-
* `algorithm` parameter which determines the key length. It uses cryptographically secure random
|
|
149
|
-
* number generation to ensure the uniqueness and security of the key. The key is returned in JWK
|
|
150
|
-
* format.
|
|
151
|
-
*
|
|
152
|
-
* The generated key includes the following components:
|
|
153
|
-
* - `kty`: Key Type, set to 'oct' for Octet Sequence.
|
|
154
|
-
* - `k`: The symmetric key component, base64url-encoded.
|
|
155
|
-
* - `kid`: Key ID, generated based on the JWK thumbprint.
|
|
156
|
-
*
|
|
157
|
-
* @example
|
|
158
|
-
* ```ts
|
|
159
|
-
* const aesCtr = new AesCtrAlgorithm();
|
|
160
|
-
* const privateKey = await aesCtr.generateKey({ algorithm: 'A256CTR' });
|
|
161
|
-
* ```
|
|
162
|
-
*
|
|
163
|
-
* @param params - The parameters for the key generation.
|
|
164
|
-
*
|
|
165
|
-
* @returns A Promise that resolves to the generated symmetric key in JWK format.
|
|
166
|
-
*/
|
|
167
|
-
AesCtrAlgorithm.prototype.generateKey = function (_a) {
|
|
168
|
-
return __awaiter(this, arguments, void 0, function (_b) {
|
|
169
|
-
var length, privateKey;
|
|
170
|
-
var algorithm = _b.algorithm;
|
|
171
|
-
return __generator(this, function (_c) {
|
|
172
|
-
switch (_c.label) {
|
|
173
|
-
case 0:
|
|
174
|
-
length = { A128CTR: 128, A192CTR: 192, A256CTR: 256 }[algorithm];
|
|
175
|
-
return [4 /*yield*/, aes_ctr_js_1.AesCtr.generateKey({ length: length })];
|
|
176
|
-
case 1:
|
|
177
|
-
privateKey = _c.sent();
|
|
178
|
-
// Set the `alg` property based on the specified algorithm.
|
|
179
|
-
privateKey.alg = algorithm;
|
|
180
|
-
return [2 /*return*/, privateKey];
|
|
181
|
-
}
|
|
182
|
-
});
|
|
183
|
-
});
|
|
184
|
-
};
|
|
185
|
-
return AesCtrAlgorithm;
|
|
186
|
-
}(crypto_algorithm_js_1.CryptoAlgorithm));
|
|
187
|
-
exports.AesCtrAlgorithm = AesCtrAlgorithm;
|
|
188
|
-
//# sourceMappingURL=aes-ctr.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"aes-ctr.js","sourceRoot":"","sources":["../../../src/algorithms/aes-ctr.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKA,uDAAkD;AAClD,6DAAwD;AA4BxD;;;;;;;;GAQG;AACH;IAAqC,mCAAe;IAApD;;IAgHA,CAAC;IA5GC;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IACU,iCAAO,GAApB,UAAqB,MACS;;;;gBAEtB,SAAS,GAAG,mBAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;gBAEzC,sBAAO,SAAS,EAAC;;;KAClB;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IACU,iCAAO,GAApB,UAAqB,MACS;;;;gBAEtB,UAAU,GAAG,mBAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;gBAE1C,sBAAO,UAAU,EAAC;;;KACnB;IAED;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACU,qCAAW,GAAxB;4DAAyB,EACA;;gBADE,SAAS,eAAA;;;;wBAI5B,MAAM,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,SAAS,CAAoB,CAAC;wBAGvE,qBAAM,mBAAM,CAAC,WAAW,CAAC,EAAE,MAAM,QAAA,EAAE,CAAC,EAAA;;wBAAjD,UAAU,GAAG,SAAoC;wBAEvD,2DAA2D;wBAC3D,UAAU,CAAC,GAAG,GAAG,SAAS,CAAC;wBAE3B,sBAAO,UAAU,EAAC;;;;KACnB;IACH,sBAAC;AAAD,CAAC,AAhHD,CAAqC,qCAAe,GAgHnD;AAhHY,0CAAe"}
|
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
-
});
|
|
25
|
-
};
|
|
26
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
27
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
28
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
29
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
30
|
-
function step(op) {
|
|
31
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
32
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
33
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
34
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
35
|
-
switch (op[0]) {
|
|
36
|
-
case 0: case 1: t = op; break;
|
|
37
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
38
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
39
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
40
|
-
default:
|
|
41
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
42
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
43
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
44
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
45
|
-
if (t[2]) _.ops.pop();
|
|
46
|
-
_.trys.pop(); continue;
|
|
47
|
-
}
|
|
48
|
-
op = body.call(thisArg, _);
|
|
49
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
50
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
|
-
exports.AesGcmAlgorithm = void 0;
|
|
55
|
-
var crypto_algorithm_js_1 = require("./crypto-algorithm.js");
|
|
56
|
-
var aes_gcm_js_1 = require("../primitives/aes-gcm.js");
|
|
57
|
-
/**
|
|
58
|
-
* The `AesGcmAlgorithm` class provides a concrete implementation for cryptographic operations using
|
|
59
|
-
* the AES algorithm in Galois/Counter Mode (GCM). This class implements both
|
|
60
|
-
* {@link Cipher | `Cipher`} and { @link KeyGenerator | `KeyGenerator`} interfaces, providing
|
|
61
|
-
* key generation, encryption, and decryption features.
|
|
62
|
-
*
|
|
63
|
-
* This class is typically accessed through implementations that extend the
|
|
64
|
-
* {@link CryptoApi | `CryptoApi`} interface.
|
|
65
|
-
*/
|
|
66
|
-
var AesGcmAlgorithm = /** @class */ (function (_super) {
|
|
67
|
-
__extends(AesGcmAlgorithm, _super);
|
|
68
|
-
function AesGcmAlgorithm() {
|
|
69
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Decrypts the provided data using AES-GCM.
|
|
73
|
-
*
|
|
74
|
-
* @remarks
|
|
75
|
-
* This method performs AES-GCM decryption on the given encrypted data using the specified key.
|
|
76
|
-
* It requires an initialization vector (IV), the encrypted data along with the decryption key,
|
|
77
|
-
* and optionally, additional authenticated data (AAD). The method returns the decrypted data as a
|
|
78
|
-
* Uint8Array. The optional `tagLength` parameter specifies the size in bits of the authentication
|
|
79
|
-
* tag used when encrypting the data. If not specified, the default tag length of 128 bits is
|
|
80
|
-
* used.
|
|
81
|
-
*
|
|
82
|
-
* @example
|
|
83
|
-
* ```ts
|
|
84
|
-
* const aesGcm = new AesGcmAlgorithm();
|
|
85
|
-
* const encryptedData = new Uint8Array([...]); // Encrypted data
|
|
86
|
-
* const iv = new Uint8Array([...]); // Initialization vector used during encryption
|
|
87
|
-
* const additionalData = new Uint8Array([...]); // Optional additional authenticated data
|
|
88
|
-
* const key = { ... }; // A Jwk object representing the AES key
|
|
89
|
-
* const decryptedData = await aesGcm.decrypt({
|
|
90
|
-
* data: encryptedData,
|
|
91
|
-
* iv,
|
|
92
|
-
* additionalData,
|
|
93
|
-
* key,
|
|
94
|
-
* tagLength: 128 // Optional tag length in bits
|
|
95
|
-
* });
|
|
96
|
-
* ```
|
|
97
|
-
*
|
|
98
|
-
* @param params - The parameters for the decryption operation.
|
|
99
|
-
*
|
|
100
|
-
* @returns A Promise that resolves to the decrypted data as a Uint8Array.
|
|
101
|
-
*/
|
|
102
|
-
AesGcmAlgorithm.prototype.decrypt = function (params) {
|
|
103
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
104
|
-
var plaintext;
|
|
105
|
-
return __generator(this, function (_a) {
|
|
106
|
-
plaintext = aes_gcm_js_1.AesGcm.decrypt(params);
|
|
107
|
-
return [2 /*return*/, plaintext];
|
|
108
|
-
});
|
|
109
|
-
});
|
|
110
|
-
};
|
|
111
|
-
/**
|
|
112
|
-
* Encrypts the provided data using AES-GCM.
|
|
113
|
-
*
|
|
114
|
-
* @remarks
|
|
115
|
-
* This method performs AES-GCM encryption on the given data using the specified key.
|
|
116
|
-
* It requires an initialization vector (IV), the encrypted data along with the decryption key,
|
|
117
|
-
* and optionally, additional authenticated data (AAD). The method returns the encrypted data as a
|
|
118
|
-
* Uint8Array. The optional `tagLength` parameter specifies the size in bits of the authentication
|
|
119
|
-
* tag generated in the encryption operation and used for authentication in the corresponding
|
|
120
|
-
* decryption. If not specified, the default tag length of 128 bits is used.
|
|
121
|
-
*
|
|
122
|
-
* @example
|
|
123
|
-
* ```ts
|
|
124
|
-
* const aesGcm = new AesGcmAlgorithm();
|
|
125
|
-
* const data = new TextEncoder().encode('Messsage');
|
|
126
|
-
* const iv = new Uint8Array([...]); // Initialization vector
|
|
127
|
-
* const additionalData = new Uint8Array([...]); // Optional additional authenticated data
|
|
128
|
-
* const key = { ... }; // A Jwk object representing an AES key
|
|
129
|
-
* const encryptedData = await aesGcm.encrypt({
|
|
130
|
-
* data,
|
|
131
|
-
* iv,
|
|
132
|
-
* additionalData,
|
|
133
|
-
* key,
|
|
134
|
-
* tagLength: 128 // Optional tag length in bits
|
|
135
|
-
* });
|
|
136
|
-
* ```
|
|
137
|
-
*
|
|
138
|
-
* @param params - The parameters for the encryption operation.
|
|
139
|
-
*
|
|
140
|
-
* @returns A Promise that resolves to the encrypted data as a Uint8Array.
|
|
141
|
-
*/
|
|
142
|
-
AesGcmAlgorithm.prototype.encrypt = function (params) {
|
|
143
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
144
|
-
var ciphertext;
|
|
145
|
-
return __generator(this, function (_a) {
|
|
146
|
-
ciphertext = aes_gcm_js_1.AesGcm.encrypt(params);
|
|
147
|
-
return [2 /*return*/, ciphertext];
|
|
148
|
-
});
|
|
149
|
-
});
|
|
150
|
-
};
|
|
151
|
-
/**
|
|
152
|
-
* Generates a symmetric key for AES in Galois/Counter Mode (GCM) in JSON Web Key (JWK) format.
|
|
153
|
-
*
|
|
154
|
-
* @remarks
|
|
155
|
-
* This method generates a symmetric AES key for use in GCM mode, based on the specified
|
|
156
|
-
* `algorithm` parameter which determines the key length. It uses cryptographically secure random
|
|
157
|
-
* number generation to ensure the uniqueness and security of the key. The key is returned in JWK
|
|
158
|
-
* format.
|
|
159
|
-
*
|
|
160
|
-
* The generated key includes the following components:
|
|
161
|
-
* - `kty`: Key Type, set to 'oct' for Octet Sequence.
|
|
162
|
-
* - `k`: The symmetric key component, base64url-encoded.
|
|
163
|
-
* - `kid`: Key ID, generated based on the JWK thumbprint.
|
|
164
|
-
*
|
|
165
|
-
* @example
|
|
166
|
-
* ```ts
|
|
167
|
-
* const aesGcm = new AesGcmAlgorithm();
|
|
168
|
-
* const privateKey = await aesGcm.generateKey({ algorithm: 'A256GCM' });
|
|
169
|
-
* ```
|
|
170
|
-
*
|
|
171
|
-
* @param params - The parameters for the key generation.
|
|
172
|
-
*
|
|
173
|
-
* @returns A Promise that resolves to the generated symmetric key in JWK format.
|
|
174
|
-
*/
|
|
175
|
-
AesGcmAlgorithm.prototype.generateKey = function (_a) {
|
|
176
|
-
return __awaiter(this, arguments, void 0, function (_b) {
|
|
177
|
-
var length, privateKey;
|
|
178
|
-
var algorithm = _b.algorithm;
|
|
179
|
-
return __generator(this, function (_c) {
|
|
180
|
-
switch (_c.label) {
|
|
181
|
-
case 0:
|
|
182
|
-
length = { A128GCM: 128, A192GCM: 192, A256GCM: 256 }[algorithm];
|
|
183
|
-
return [4 /*yield*/, aes_gcm_js_1.AesGcm.generateKey({ length: length })];
|
|
184
|
-
case 1:
|
|
185
|
-
privateKey = _c.sent();
|
|
186
|
-
// Set the `alg` property based on the specified algorithm.
|
|
187
|
-
privateKey.alg = algorithm;
|
|
188
|
-
return [2 /*return*/, privateKey];
|
|
189
|
-
}
|
|
190
|
-
});
|
|
191
|
-
});
|
|
192
|
-
};
|
|
193
|
-
return AesGcmAlgorithm;
|
|
194
|
-
}(crypto_algorithm_js_1.CryptoAlgorithm));
|
|
195
|
-
exports.AesGcmAlgorithm = AesGcmAlgorithm;
|
|
196
|
-
//# sourceMappingURL=aes-gcm.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"aes-gcm.js","sourceRoot":"","sources":["../../../src/algorithms/aes-gcm.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKA,6DAAwD;AACxD,uDAAuE;AAmDvE;;;;;;;;GAQG;AACH;IAAqC,mCAAe;IAApD;;IAwHA,CAAC;IApHC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8BG;IACU,iCAAO,GAApB,UAAqB,MACS;;;;gBAEtB,SAAS,GAAG,mBAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;gBAEzC,sBAAO,SAAS,EAAC;;;KAClB;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8BG;IACU,iCAAO,GAApB,UAAqB,MACS;;;;gBAEtB,UAAU,GAAG,mBAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;gBAE1C,sBAAO,UAAU,EAAC;;;KACnB;IAED;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACU,qCAAW,GAAxB;4DAAyB,EACA;;gBADE,SAAS,eAAA;;;;wBAI5B,MAAM,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,SAAS,CAAoB,CAAC;wBAGvE,qBAAM,mBAAM,CAAC,WAAW,CAAC,EAAE,MAAM,QAAA,EAAE,CAAC,EAAA;;wBAAjD,UAAU,GAAG,SAAoC;wBAEvD,2DAA2D;wBAC3D,UAAU,CAAC,GAAG,GAAG,SAAS,CAAC;wBAE3B,sBAAO,UAAU,EAAC;;;;KACnB;IACH,sBAAC;AAAD,CAAC,AAxHD,CAAqC,qCAAe,GAwHnD;AAxHY,0CAAe"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CryptoAlgorithm = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Base class for all cryptographic algorithm implementations.
|
|
6
|
-
*/
|
|
7
|
-
var CryptoAlgorithm = /** @class */ (function () {
|
|
8
|
-
function CryptoAlgorithm() {
|
|
9
|
-
}
|
|
10
|
-
return CryptoAlgorithm;
|
|
11
|
-
}());
|
|
12
|
-
exports.CryptoAlgorithm = CryptoAlgorithm;
|
|
13
|
-
//# sourceMappingURL=crypto-algorithm.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"crypto-algorithm.js","sourceRoot":"","sources":["../../../src/algorithms/crypto-algorithm.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH;IAAA;IAAuC,CAAC;IAAD,sBAAC;AAAD,CAAC,AAAxC,IAAwC;AAAlB,0CAAe"}
|