CryptoKey: extractable プロパティ

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

安全なコンテキスト用: この機能は一部またはすべての対応しているブラウザーにおいて、安全なコンテキスト (HTTPS) でのみ利用できます。

extractableCryptoKey インターフェイスの読み取り専用プロパティで、SubtleCrypto.exportKey() または SubtleCrypto.wrapKey() を使用してキーを抽出できるかどうかを示します。

キーがエクスポートできない場合は、 exportKey()wrapKey() では抽出しようとして例外を発生します。

論理値で、キーがエクスポート可能であれば true、不可能であれば false となります。

この例では、キーをエクスポートできない場合、「エクスポート」ボタンは無効になり、待ち受けするリスナーも追加されません。

js
// 指定されたキーをエクスポートし、"exported-key" 空間に書き込みます。
async function exportCryptoKey(key) {
  const exported = await window.crypto.subtle.exportKey("raw", key);
  const exportedKeyBuffer = new Uint8Array(exported);

  const exportKeyOutput = document.querySelector(".exported-key");
  exportKeyOutput.textContent = `[${exportedKeyBuffer}]`;
}

// キーが抽出可能かどうかによって、exportButton を有効または無効にします。
function setExportButton(key) {
  const exportButton = document.querySelector(".raw");

  // キーが抽出できない場合は、ボタンを無効にする
  exportButton.disabled = !key.extractable;
  if (key.extractable) {
    // イベントリスナーを追加してキーを抽出する
    exportButton.addEventListener("click", () => {
      exportCryptoKey(key);
    });
  }
}

// 暗号化/復号する秘密鍵を生成する。
// 次に、「エクスポート」ボタンでイベントリスナーを有効にし、設定する。
window.crypto.subtle
  .generateKey(
    {
      name: "AES-GCM",
      length: 256,
    },
    true,
    ["encrypt", "decrypt"],
  )
  .then(setExportButton(key));

仕様書

Specification
Web Cryptography API
# dom-cryptokey-extractable

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
extractable

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
Partial support
Partial support
Has more compatibility info.