Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. Web APIs
  3. CryptoKey
  4. type

CryptoKey: type property

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⁩.

Secure context: This feature is available only insecure contexts (HTTPS), in some or allsupporting browsers.

Note: This feature is available inWeb Workers.

The read-onlytype property of theCryptoKey interface indicates which kind of key is represented by the object. It can have the following values:

Value

One of the following strings:"secret","private", or"public".

Examples

This function verifies a message usingSubtleCrypto.verify() and a public key given in the parameter. If the key is not a public key, it always returns"invalid", as such verification is fundamentally insecure.

js
async function verifyMessage(publicKey) {  const signatureValue = document.querySelector(    ".rsassa-pkcs1 .signature-value",  );  signatureValue.classList.remove("valid", "invalid");  let result = false; // By default, it is invalid  if (publicKey.type === "public") {    const encoded = getMessageEncoding();    result = await window.crypto.subtle.verify(      "RSASSA-PKCS1-v1_5",      publicKey,      signature,      encoded,    );  }  signatureValue.classList.add(result ? "valid" : "invalid");}

Specifications

Specification
Web Cryptography Level 2
# dom-cryptokey-type

Browser compatibility

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp