CryptoKey: algorithm プロパティ

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) でのみ利用できます。

algorithmCryptoKey インターフェイスの読み取り専用プロパティで、このキーを使用できるアルゴリズムを記述したオブジェクトと、関連する追加の引数を返します。

返されるオブジェクトは、キーを生成する際に使用するアルゴリズムによって異なります。

以下のいずれかに一致するオブジェクトです。

js
const rawKey = window.crypto.getRandomValues(new Uint8Array(16));

// 生のバイト列を格納する ArrayBuffer から AES 秘密鍵をインポートする
// バイト列を格納する ArrayBuffer 文字列を引数にとり、
// 秘密鍵を表す CryptoKey に解決するプロミスを返す
function importSecretKey(rawKey) {
  return window.crypto.subtle.importKey("raw", rawKey, "AES-GCM", true, [
    "encrypt",
    "decrypt",
  ]);
}

const key = importSecretKey(rawKey);
console.log(`このキーは ${key.algorithm} アルゴリズムで使われるものです。`);

仕様書

Specification
Web Cryptography API
# dom-cryptokey-algorithm

ブラウザーの互換性

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
algorithm

Legend

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

Full support
Full support