Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 788292 of SubtleCrypto.sign()

  • Revision slug: Web/API/SubtleCrypto/sign
  • Revision title: SubtleCrypto.sign()
  • Revision id: 788292
  • Created:
  • Creator: dskloet
  • Is current revision? No
  • Comment

Revision Content

{{APIRef("Web Crypto API")}}

The SubtleCrypto.sign() method returns a {{jsxref("Promise")}} containing the {{glossary("signature")}} corresponding to the text, algorithm and {{glossary("key")}} given as parameters.

Syntax

var signature = crypto.sign(algo, key, text2sign);

Parameters

  • text2sign is a {{jsxref("ArrayBuffer")}} or an {{jsxref("ArrayBufferView")}} containing the data to be signed.
  • key is a {{domxref("CryptoKey")}} containing the private key to be used for signing.
  • algo is a {{domxref("DOMString")}} defining the signature function to use. Supported values are: HMAC, RSASSA-PKCS1-v1_5, and ECDSA.

Return value

  • signature is a {{jsxref("Promise")}} that returns the signature on success.

Exceptions

The promise is rejected when the following exception is encountered:

  • {{exception("InvalidAccessError")}} when the signing key is not a key for the request signing algorithm or when trying to use an algorithm that is either unknown or isn't suitable for signing.

Specifications

Specification Status Comment
{{ SpecName('Web Crypto API', '#dfn-SubtleCrypto-method-sign', 'SubtleCrypto.sign()') }} {{ Spec2('Web Crypto API') }} Initial definition.

Browser compatibility

{{ CompatibilityTable() }}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support {{ CompatChrome(37) }} {{ CompatGeckoDesktop(34) }} {{ CompatNo() }} {{ CompatUnknown() }} {{ CompatNo }}
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support {{CompatVersionUnknown}} 37 {{ CompatGeckoMobile(34) }} {{ CompatNo }} {{ CompatUnknown() }} {{ CompatNo }}

See also

  • {{domxref("Crypto")}} and {{domxref("Crypto.subtle")}}.
  • {{domxref("SubtleCrypto")}}, the interface it belongs to.

Revision Source

<p>{{APIRef("Web Crypto API")}}</p>

<p>The <code><strong>SubtleCrypto.sign()</strong></code> method returns a {{jsxref("Promise")}} containing the {{glossary("signature")}} corresponding to the text, algorithm and {{glossary("key")}} given as parameters.</p>

<h2 id="Syntax">Syntax</h2>

<pre class="syntaxbox">
var <em>signature</em> = <em>crypto</em><code>.sign(<em>algo</em>, <em>key</em>, <em>text2sign</em>)</code>;
</pre>

<h3 id="Parameters">Parameters</h3>

<ul>
 <li><em><code>text2sign</code></em> is a {{jsxref("ArrayBuffer")}} or an {{jsxref("ArrayBufferView")}} containing the data to be signed.</li>
 <li><em>key</em> is a {{domxref("CryptoKey")}} containing the private key to be used for signing.</li>
 <li><em><code>algo</code></em> is a {{domxref("DOMString")}} defining the signature function to use. Supported values are: <code>HMAC</code>, <code>RSASSA-PKCS1-v1_5</code>, and <code>ECDSA</code>.</li>
</ul>

<h3 id="Return_value">Return value</h3>

<ul>
 <li><code><em>signature</em></code> is a {{jsxref("Promise")}} that returns the signature on success.</li>
</ul>

<h3 id="Exceptions">Exceptions</h3>

<p>The promise is rejected when the following exception is encountered:</p>

<ul>
 <li>{{exception("InvalidAccessError")}} when the signing key is not a key for the request signing algorithm or when trying to use an algorithm that is either unknown or isn't suitable for signing.</li>
</ul>

<h2 id="Specifications">Specifications</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
  <tr>
   <td>{{ SpecName('Web Crypto API', '#dfn-SubtleCrypto-method-sign', 'SubtleCrypto.sign()') }}</td>
   <td>{{ Spec2('Web Crypto API') }}</td>
   <td>Initial definition.</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility">Browser compatibility</h2>

<p>{{ CompatibilityTable() }}</p>

<div id="compat-desktop">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Chrome</th>
   <th>Firefox (Gecko)</th>
   <th>Internet Explorer</th>
   <th>Opera</th>
   <th>Safari</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{ CompatChrome(37) }}</td>
   <td>{{ CompatGeckoDesktop(34) }}</td>
   <td>{{ CompatNo() }}</td>
   <td>{{ CompatUnknown() }}</td>
   <td>{{ CompatNo }}</td>
  </tr>
 </tbody>
</table>
</div>

<div id="compat-mobile">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Android</th>
   <th>Chrome for Android</th>
   <th>Firefox Mobile (Gecko)</th>
   <th>IE Mobile</th>
   <th>Opera Mobile</th>
   <th>Safari Mobile</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>37</td>
   <td>{{ CompatGeckoMobile(34) }}</td>
   <td>{{ CompatNo }}</td>
   <td>{{ CompatUnknown() }}</td>
   <td>{{ CompatNo }}</td>
  </tr>
 </tbody>
</table>
</div>

<h2 id="See_also">See also</h2>

<ul>
 <li>{{domxref("Crypto")}} and {{domxref("Crypto.subtle")}}.</li>
 <li>{{domxref("SubtleCrypto")}}, the interface it belongs to.</li>
</ul>
Revert to this revision