UNPKG

devextreme

Version:

JavaScript/TypeScript Component Suite for Responsive Web Development

80 lines (79 loc) 2.32 kB
/** * DevExtreme (esm/__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/ */ import { base64ToBytes, bigIntFromBytes } from "../byte_utils"; import { pad } from "../pkcs1"; import { compareSignatures } from "../rsa_bigint"; import { sha1 } from "../sha1"; import { DECODE_MAP } from "./const"; export const bit = shift => 1n << BigInt(shift); export 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: base64ToBytes(modulusMatch[1]), exponent: Number(bigIntFromBytes(base64ToBytes(exponentMatch[1]))) } }; export const encodeString = (text, encode) => "function" === typeof encode ? encode(text) : text; export 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 }; export const shiftDecodeText = text => shiftText(text, DECODE_MAP); const DOT_NET_TICKS_EPOCH_OFFSET = 621355968000000000n; const DOT_NET_TICKS_PER_MS = 10000n; const DOT_NET_MAX_VALUE_TICKS = 3155378975999999999n; export function dotNetTicksToMs(ticksStr) { const ticks = BigInt(ticksStr); if (ticks >= 3155378975999999999n) { return 1 / 0 } return Number((ticks - 621355968000000000n) / 10000n) } export const verifyHash = (xmlKey, data, signature) => { const { modulus: modulus, exponent: exponent } = parseRsaXml(xmlKey); const key = { n: modulus, e: exponent }; const sign = base64ToBytes(signature); return compareSignatures({ key: key, signature: sign, actual: pad(sha1(data)) }) };