UNPKG

devextreme

Version:

JavaScript/TypeScript Component Suite for Responsive Web Development

83 lines (81 loc) 2.82 kB
/** * DevExtreme (cjs/__internal/core/license/lcp_key_validation/utils.js) * Version: 25.2.7 * Build date: Tue May 05 2026 * * Copyright (c) 2012 - 2026 Developer Express Inc. ALL RIGHTS RESERVED * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/ */ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.bit = void 0; exports.dotNetTicksToMs = dotNetTicksToMs; exports.verifyHash = exports.shiftText = exports.shiftDecodeText = exports.parseRsaXml = exports.encodeString = void 0; var _byte_utils = require("../byte_utils"); var _pkcs = require("../pkcs1"); var _rsa_bigint = require("../rsa_bigint"); var _sha = require("../sha1"); var _const = require("./const"); const bit = shift => 1n << BigInt(shift); exports.bit = bit; const parseRsaXml = xml => { const modulusMatch = /<Modulus>([^<]+)<\/Modulus>/.exec(xml); const exponentMatch = /<Exponent>([^<]+)<\/Exponent>/.exec(xml); if (!modulusMatch || !exponentMatch) { throw new Error("Invalid RSA XML key.") } return { modulus: (0, _byte_utils.base64ToBytes)(modulusMatch[1]), exponent: Number((0, _byte_utils.bigIntFromBytes)((0, _byte_utils.base64ToBytes)(exponentMatch[1]))) } }; exports.parseRsaXml = parseRsaXml; const encodeString = (text, encode) => "function" === typeof encode ? encode(text) : text; exports.encodeString = encodeString; const shiftText = (text, map) => { if (!text) { return text || "" } let result = ""; for (let i = 0; i < text.length; i += 1) { const charCode = text.charCodeAt(i); if (charCode < map.length) { result += map[charCode] } else { result += text[i] } } return result }; exports.shiftText = shiftText; const shiftDecodeText = text => shiftText(text, _const.DECODE_MAP); exports.shiftDecodeText = shiftDecodeText; const DOT_NET_TICKS_EPOCH_OFFSET = 621355968000000000n; const DOT_NET_TICKS_PER_MS = 10000n; const DOT_NET_MAX_VALUE_TICKS = 3155378975999999999n; function dotNetTicksToMs(ticksStr) { const ticks = BigInt(ticksStr); if (ticks >= DOT_NET_MAX_VALUE_TICKS) { return 1 / 0 } return Number((ticks - DOT_NET_TICKS_EPOCH_OFFSET) / DOT_NET_TICKS_PER_MS) } const verifyHash = (xmlKey, data, signature) => { const { modulus: modulus, exponent: exponent } = parseRsaXml(xmlKey); const key = { n: modulus, e: exponent }; const sign = (0, _byte_utils.base64ToBytes)(signature); return (0, _rsa_bigint.compareSignatures)({ key: key, signature: sign, actual: (0, _pkcs.pad)((0, _sha.sha1)(data)) }) }; exports.verifyHash = verifyHash;