perimeterx-js-core 0.22.0 → 0.22.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/lib/cjs/impl/cipher/CryptoJsCipherUtils.js +69 -0
- package/lib/cjs/utils/constants.js +1 -1
- package/lib/esm/impl/cipher/CryptoJsCipherUtils.js +18 -0
- package/lib/esm/utils/constants.js +1 -1
- package/lib/types/impl/cipher/CryptoJsCipherUtils.d.ts +4 -0
- package/lib/types/utils/constants.d.ts +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
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;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
+
};
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.CryptoJsCipherUtils = void 0;
|
|
43
|
+
var crypto_js_1 = __importDefault(require("crypto-js"));
|
|
44
|
+
var CryptoJsCipherUtils = /** @class */ (function () {
|
|
45
|
+
function CryptoJsCipherUtils() {
|
|
46
|
+
}
|
|
47
|
+
CryptoJsCipherUtils.prototype.pbkdf2Decrypt = function (secret, encryptedString, iterations, salt, options) {
|
|
48
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
49
|
+
var ivlen, keylen, encodedPassword, encodedSalt, pbkdf2, key, iv, encodedData, data;
|
|
50
|
+
return __generator(this, function (_a) {
|
|
51
|
+
ivlen = (options === null || options === void 0 ? void 0 : options.ivlen) || 16;
|
|
52
|
+
keylen = (options === null || options === void 0 ? void 0 : options.keylen) || 32;
|
|
53
|
+
encodedPassword = crypto_js_1.default.enc.Utf8.parse(secret);
|
|
54
|
+
encodedSalt = crypto_js_1.default.enc.Base64.parse(salt);
|
|
55
|
+
pbkdf2 = crypto_js_1.default.PBKDF2(encodedPassword, encodedSalt, {
|
|
56
|
+
iterations: iterations,
|
|
57
|
+
keySize: (ivlen + keylen) / 4,
|
|
58
|
+
}).toString(crypto_js_1.default.enc.Hex);
|
|
59
|
+
key = crypto_js_1.default.enc.Hex.parse(pbkdf2.slice(0, keylen * 2));
|
|
60
|
+
iv = crypto_js_1.default.enc.Hex.parse(pbkdf2.slice(keylen * 2));
|
|
61
|
+
encodedData = crypto_js_1.default.AES.decrypt(encryptedString, key, { iv: iv, mode: crypto_js_1.default.mode.CBC });
|
|
62
|
+
data = encodedData.toString(crypto_js_1.default.enc.Utf8);
|
|
63
|
+
return [2 /*return*/, data];
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
};
|
|
67
|
+
return CryptoJsCipherUtils;
|
|
68
|
+
}());
|
|
69
|
+
exports.CryptoJsCipherUtils = CryptoJsCipherUtils;
|
|
@@ -14,4 +14,4 @@ exports.PUSH_DATA_FEATURE_HEADER_NAME = 'x-px-feature';
|
|
|
14
14
|
exports.EMAIL_ADDRESS_REGEX = /^[a-zA-Z0-9_+&*-]+(?:\.[a-zA-Z0-9_+&*-]+)*@(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,7}$/;
|
|
15
15
|
exports.URL_REGEX = /^(https?\:)\/\/(([^@\s:]+):?([^@\s]*)@)?(([^:\/?#]*)(?:\:([0-9]+))?)([\/]{0,1}[^?#]*)(\?[^#]*|)(#.*|)$/;
|
|
16
16
|
exports.REGEX_STRUCTURE = /^\/(.+?)\/([gimsuyvd]*)$/;
|
|
17
|
-
exports.CORE_MODULE_VERSION = 'JS Core 0.22.
|
|
17
|
+
exports.CORE_MODULE_VERSION = 'JS Core 0.22.1';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import CryptoJS from 'crypto-js';
|
|
2
|
+
export class CryptoJsCipherUtils {
|
|
3
|
+
async pbkdf2Decrypt(secret, encryptedString, iterations, salt, options) {
|
|
4
|
+
const ivlen = options?.ivlen || 16;
|
|
5
|
+
const keylen = options?.keylen || 32;
|
|
6
|
+
const encodedPassword = CryptoJS.enc.Utf8.parse(secret);
|
|
7
|
+
const encodedSalt = CryptoJS.enc.Base64.parse(salt);
|
|
8
|
+
const pbkdf2 = CryptoJS.PBKDF2(encodedPassword, encodedSalt, {
|
|
9
|
+
iterations: iterations,
|
|
10
|
+
keySize: (ivlen + keylen) / 4,
|
|
11
|
+
}).toString(CryptoJS.enc.Hex);
|
|
12
|
+
const key = CryptoJS.enc.Hex.parse(pbkdf2.slice(0, keylen * 2));
|
|
13
|
+
const iv = CryptoJS.enc.Hex.parse(pbkdf2.slice(keylen * 2));
|
|
14
|
+
const encodedData = CryptoJS.AES.decrypt(encryptedString, key, { iv: iv, mode: CryptoJS.mode.CBC });
|
|
15
|
+
const data = encodedData.toString(CryptoJS.enc.Utf8);
|
|
16
|
+
return data;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -11,4 +11,4 @@ export const PUSH_DATA_FEATURE_HEADER_NAME = 'x-px-feature';
|
|
|
11
11
|
export const EMAIL_ADDRESS_REGEX = /^[a-zA-Z0-9_+&*-]+(?:\.[a-zA-Z0-9_+&*-]+)*@(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,7}$/;
|
|
12
12
|
export const URL_REGEX = /^(https?\:)\/\/(([^@\s:]+):?([^@\s]*)@)?(([^:\/?#]*)(?:\:([0-9]+))?)([\/]{0,1}[^?#]*)(\?[^#]*|)(#.*|)$/;
|
|
13
13
|
export const REGEX_STRUCTURE = /^\/(.+?)\/([gimsuyvd]*)$/;
|
|
14
|
-
export const CORE_MODULE_VERSION = 'JS Core 0.22.
|
|
14
|
+
export const CORE_MODULE_VERSION = 'JS Core 0.22.1';
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ICipherUtils, Pbkdf2DecryptOptions } from '../../utils';
|
|
2
|
+
export declare class CryptoJsCipherUtils implements ICipherUtils {
|
|
3
|
+
pbkdf2Decrypt(secret: string, encryptedString: string, iterations: number, salt: string, options?: Pbkdf2DecryptOptions): Promise<string>;
|
|
4
|
+
}
|
|
@@ -11,4 +11,4 @@ export declare const PUSH_DATA_FEATURE_HEADER_NAME = "x-px-feature";
|
|
|
11
11
|
export declare const EMAIL_ADDRESS_REGEX: RegExp;
|
|
12
12
|
export declare const URL_REGEX: RegExp;
|
|
13
13
|
export declare const REGEX_STRUCTURE: RegExp;
|
|
14
|
-
export declare const CORE_MODULE_VERSION = "JS Core 0.22.
|
|
14
|
+
export declare const CORE_MODULE_VERSION = "JS Core 0.22.1";
|