PHP WebShell

Текущая директория: /opt/BitGoJS/node_modules/@hashgraph/cryptography/lib/primitive

Просмотр файла: pbkdf2.native.cjs

"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.deriveKey = deriveKey;

var _hmac = require("./hmac.cjs");

var utf8 = _interopRequireWildcard(require("../encoding/utf8.cjs"));

var hex = _interopRequireWildcard(require("../encoding/hex.cjs"));

var _cryptoJs = _interopRequireDefault(require("crypto-js"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

/**
 * @param {HashAlgorithm} algorithm
 * @param {Uint8Array | string} password
 * @param {Uint8Array | string} salt
 * @param {number} iterations
 * @param {number} length
 * @returns {Promise<Uint8Array>}
 */
async function deriveKey(algorithm, password, salt, iterations, length) {
  const pass = typeof password === "string" ? // Valid ASCII is also valid UTF-8 so encoding the password as UTF-8
  // should be fine if only valid ASCII characters are used in the password
  utf8.encode(password) : password;
  const nacl = typeof salt === "string" ? utf8.encode(salt) : salt;

  const password_ = _cryptoJs.default.enc.Hex.parse(hex.encode(pass));

  const nacl_ = _cryptoJs.default.enc.Hex.parse(hex.encode(nacl));

  let hasher;

  switch (algorithm) {
    case _hmac.HashAlgorithm.Sha256:
      hasher = _cryptoJs.default.algo.SHA256;
      break;

    case _hmac.HashAlgorithm.Sha384:
      hasher = _cryptoJs.default.algo.SHA384;
      break;

    case _hmac.HashAlgorithm.Sha512:
      hasher = _cryptoJs.default.algo.SHA512;
      break;

    default:
      throw new Error("(BUG) Non-Exhaustive switch statement for algorithms");
  }

  const cfg = {
    keySize: length / 4,
    hasher,
    iterations
  };
  return Promise.resolve(hex.decode(_cryptoJs.default.PBKDF2(password_, nacl_, cfg).toString(_cryptoJs.default.enc.Hex)));
}

Выполнить команду


Для локальной разработки. Не используйте в интернете!