PHP WebShell

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

Просмотр файла: aes.browser.cjs

"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.CipherAlgorithm = void 0;
exports.createCipheriv = createCipheriv;
exports.createDecipheriv = createDecipheriv;
const CipherAlgorithm = {
  Aes128Ctr: "AES-128-CTR",
  Aes128Cbc: "AES-128-CBC"
};

/**
 * @param {string} algorithm
 * @param {Uint8Array} key
 * @param {Uint8Array} iv
 * @param {Uint8Array} data
 * @returns {Promise<Uint8Array>}
 */
exports.CipherAlgorithm = CipherAlgorithm;
async function createCipheriv(algorithm, key, iv, data) {
  let algorithm_;
  switch (algorithm.toUpperCase()) {
    case CipherAlgorithm.Aes128Ctr:
      algorithm_ = {
        name: "AES-CTR",
        counter: iv,
        length: 128
      };
      break;
    case CipherAlgorithm.Aes128Cbc:
      algorithm_ = {
        name: "AES-CBC",
        iv: iv
      };
      break;
    default:
      throw new Error("(BUG) non-exhaustive switch statement for CipherAlgorithm");
  }
  const key_ = await window.crypto.subtle.importKey("raw", key, algorithm_.name, false, ["encrypt"]);
  return new Uint8Array(
  // https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/encrypt#return_value
  /** @type {ArrayBuffer} */
  // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
  await window.crypto.subtle.encrypt(algorithm_, key_, data));
}

/**
 * @param {string} algorithm
 * @param {Uint8Array} key
 * @param {Uint8Array} iv
 * @param {Uint8Array} data
 * @returns {Promise<Uint8Array>}
 */
async function createDecipheriv(algorithm, key, iv, data) {
  let algorithm_;
  switch (algorithm.toUpperCase()) {
    case CipherAlgorithm.Aes128Ctr:
      algorithm_ = {
        name: "AES-CTR",
        counter: iv,
        length: 128
      };
      break;
    case CipherAlgorithm.Aes128Cbc:
      algorithm_ = {
        name: "AES-CBC",
        iv
      };
      break;
    default:
      throw new Error("(BUG) non-exhaustive switch statement for CipherAlgorithm");
  }
  const key_ = await window.crypto.subtle.importKey("raw", key, algorithm_.name, false, ["decrypt"]);
  return new Uint8Array(
  // https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/encrypt#return_value
  /** @type {ArrayBuffer} */
  // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
  await window.crypto.subtle.decrypt(algorithm_, key_, data));
}

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


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