A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developer.cdn.mozilla.net/ja/docs/Web/API/SubtleCrypto/verify below:

SubtleCrypto: verify() メソッド - Web API

SubtleCrypto: verify() メソッド

Baseline Widely available *

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

verify() は SubtleCrypto インターフェイスのメソッドで、デジタル署名を検証します。

引数として、署名を検証するための鍵、アルゴリズム固有の引数、署名、署名済み元データを取ります。署名が有効かどうかを示す論理値で履行される Promise を返します。

構文
verify(algorithm, key, signature, data)
引数
algorithm

使用するアルゴリズムを定義する文字列またはオブジェクトで、アルゴリズムによっては追加の引数もあります。 追加引数に指定された値は、対応する sign() 呼び出しに渡された値と一致しなければなりません。

key

署名に用いる鍵を格納した CryptoKey オブジェクトです。 対称鍵アルゴリズムであれば秘密鍵であり、公開鍵システムであれば公開鍵です。

signature

ArrayBuffer で、検証する署名です。

data

ArrayBuffer で、署名を検証するためのデータが入ります。

返値

論理値で履行される Promise です。署名が有効な場合は true、そうでない場合は false です。

例外

以下の例外が発生した場合、プロミスは拒否されます。

InvalidAccessError DOMException

暗号鍵がリクエストされた検証アルゴリズムの鍵でない場合、または未知のアルゴリズムか検証処理に適していないアルゴリズムを使用しようとした場合に発生します。

対応しているアルゴリズム

verify() メソッドは、 sign() メソッドと同じアルゴリズムに対応しています。

例

メモ: GitHub 上の動作例を試すことができます。

RSASSA-PKCS1-v1_5

このコードは公開鍵を使用して署名を検証します。 完全なコードは GitHub で参照してください。

/*
Fetch the contents of the "message" textbox, and encode it
in a form we can use for sign operation.
*/
function getMessageEncoding() {
  const messageBox = document.querySelector(".rsassa-pkcs1 #message");
  let message = messageBox.value;
  let enc = new TextEncoder();
  return enc.encode(message);
}

/*
Fetch the encoded message-to-sign and verify it against the stored signature.
* If it checks out, set the "valid" class on the signature.
* Otherwise set the "invalid" class.
*/
async function verifyMessage(publicKey) {
  const signatureValue = document.querySelector(
    ".rsassa-pkcs1 .signature-value",
  );
  signatureValue.classList.remove("valid", "invalid");

  let encoded = getMessageEncoding();
  let result = await window.crypto.subtle.verify(
    "RSASSA-PKCS1-v1_5",
    publicKey,
    signature,
    encoded,
  );

  signatureValue.classList.add(result ? "valid" : "invalid");
}
RSA-PSS

このコードは公開鍵を使用して署名を検証します。 完全なコードは GitHub で参照してください。

/*
Fetch the contents of the "message" textbox, and encode it
in a form we can use for sign operation.
*/
function getMessageEncoding() {
  const messageBox = document.querySelector(".rsa-pss #message");
  let message = messageBox.value;
  let enc = new TextEncoder();
  return enc.encode(message);
}

/*
Fetch the encoded message-to-sign and verify it against the stored signature.
* If it checks out, set the "valid" class on the signature.
* Otherwise set the "invalid" class.
*/
async function verifyMessage(publicKey) {
  const signatureValue = document.querySelector(".rsa-pss .signature-value");
  signatureValue.classList.remove("valid", "invalid");

  let encoded = getMessageEncoding();
  let result = await window.crypto.subtle.verify(
    {
      name: "RSA-PSS",
      saltLength: 32,
    },
    publicKey,
    signature,
    encoded,
  );

  signatureValue.classList.add(result ? "valid" : "invalid");
}
ECDSA

このコードは公開鍵を使用して署名を検証します。 完全なコードは GitHub で参照してください。

/*
Fetch the contents of the "message" textbox, and encode it
in a form we can use for sign operation.
*/
function getMessageEncoding() {
  const messageBox = document.querySelector(".ecdsa #message");
  let message = messageBox.value;
  let enc = new TextEncoder();
  return enc.encode(message);
}

/*
Fetch the encoded message-to-sign and verify it against the stored signature.
* If it checks out, set the "valid" class on the signature.
* Otherwise set the "invalid" class.
*/
async function verifyMessage(publicKey) {
  const signatureValue = document.querySelector(".ecdsa .signature-value");
  signatureValue.classList.remove("valid", "invalid");

  let encoded = getMessageEncoding();
  let result = await window.crypto.subtle.verify(
    {
      name: "ECDSA",
      hash: { name: "SHA-384" },
    },
    publicKey,
    signature,
    encoded,
  );

  signatureValue.classList.add(result ? "valid" : "invalid");
}
HMAC

このコードは署名を検証するために秘密鍵を使用します。 完全なコードは GitHub で参照してください。

/*
Fetch the contents of the "message" textbox, and encode it
in a form we can use for sign operation.
*/
function getMessageEncoding() {
  const messageBox = document.querySelector(".hmac #message");
  let message = messageBox.value;
  let enc = new TextEncoder();
  return enc.encode(message);
}

/*
Fetch the encoded message-to-sign and verify it against the stored signature.
* If it checks out, set the "valid" class on the signature.
* Otherwise set the "invalid" class.
*/
async function verifyMessage(key) {
  const signatureValue = document.querySelector(".hmac .signature-value");
  signatureValue.classList.remove("valid", "invalid");

  let encoded = getMessageEncoding();
  let result = await window.crypto.subtle.verify(
    "HMAC",
    key,
    signature,
    encoded,
  );

  signatureValue.classList.add(result ? "valid" : "invalid");
}
仕様書 ブラウザーの互換性 関連情報

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4