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 982933 of SubtleCrypto

  • Revision slug: Web/API/SubtleCrypto
  • Revision title: SubtleCrypto
  • Revision id: 982933
  • Created:
  • Creator: DirkjanOchtman
  • Is current revision? No
  • Comment Add warning from the spec to clarify that use of this API requires some crypto background

Revision Content

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

The SubtleCrypto interface represents a set of cryptographic primitives. It is available via the {{domxref("Crypto.subtle")}} properties available in a window context (via {{domxref("Window.crypto")}}).

Per the spec: "Developers making use of the SubtleCrypto interface are expected to be aware of the security concerns associated with both the design and implementation of the various algorithms provided. The raw algorithms are provided in order to allow developers maximum flexibility in implementing a variety of protocols and applications, each of which may represent the composition and security parameters in a unique manner that necessitate the use of the raw algorithms."

Properties

This interface neither inherits, nor implements, any property.

Methods

This interface doesn't inherit any method.

{{domxref("SubtleCrypto.encrypt()")}}
Returns a {{jsxref("Promise")}} of the encrypted data corresponding to the clear text, algorithm and key given as parameters.
{{domxref("SubtleCrypto.decrypt()")}}
Returns a {{jsxref("Promise")}} of the clear data corresponding to the encrypted text, algorithm and key given as parameters.
{{domxref("SubtleCrypto.sign()")}}
Returns a {{jsxref("Promise")}} of the signature corresponding to the text, algorithm and key given as parameters.
{{domxref("SubtleCrypto.verify()")}}
Returns a {{jsxref("Promise")}} of a {{jsxref("Boolean")}} value indicating if the signature given as parameter matches the text, algorithm and key also given as parameters.
{{domxref("SubtleCrypto.digest()")}}
Returns a {{jsxref("Promise")}} of a digest generated from the algorithm and text given as parameters.
{{domxref("SubtleCrypto.generateKey()")}}
Returns a {{jsxref("Promise")}} of a newly generated {{domxref("CryptoKey")}}, for symmetrical algorithms, or a {{domxref("CryptoKeyPair")}}, containing two newly generated keys, for asymmetrical algorithm, that matches the algorithm, the usages and the extractability given as parameters.
{{domxref("SubtleCrypto.deriveKey()")}}
Returns a {{jsxref("Promise")}} of a newly generated {{domxref("CryptoKey")}} derived from a master key and a specific algorithm given as parameters.
{{domxref("SubtleCrypto.deriveBits()")}}
Returns a {{jsxref("Promise")}} of a newly generated buffer of pseudo-random bits derived from a master key and a specific algorithm given as parameters.
{{domxref("SubtleCrypto.importKey()")}}
Returns a {{jsxref("Promise")}} of a {{domxref("CryptoKey")}} corresponding to the format, the algorithm, the raw key data, the usages and the extractability given as parameters.
{{domxref("SubtleCrypto.exportKey()")}}
Returns a {{jsxref("Promise")}} of a buffer containing the key in the format requested.
{{domxref("SubtleCrypto.wrapKey()")}}
Returns a {{jsxref("Promise")}} of a wrapped symmetric key for usage (transfer, storage) in insecure environments. The wrapped buffer returned is in the format given in parameters, and contains the key wrapped by the given wrapping key with the given algorithm.
{{domxref("SubtleCrypto.unwrapKey()")}}
Returns a {{jsxref("Promise")}} of a {{domxref("CryptoKey")}} corresponding to the wrapped key given in parameter.

Specifications

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

Browser compatibility

{{ CompatibilityTable() }}

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

See also

  • {{domxref("Crypto")}} and {{domxref("Crypto.subtle")}}.

Revision Source

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

<p>The <code><strong>SubtleCrypto</strong></code> interface represents a set of cryptographic primitives. It is available via the {{domxref("Crypto.subtle")}} properties available in a window context (via {{domxref("Window.crypto")}}).</p>

<div class="warning">
<p>Per the spec: "Developers making use of the SubtleCrypto interface are expected to be aware of the security concerns associated with both the design and implementation of the various algorithms provided. The raw algorithms are provided in order to allow developers maximum flexibility in implementing a variety of protocols and applications, each of which may represent the composition and security parameters in a unique manner that necessitate the use of the raw algorithms."</p>
</div>

<h2 id="Properties">Properties</h2>

<p><em>This interface neither inherits, nor implements, any property.</em></p>

<h2 id="Methods">Methods</h2>

<p>This interface doesn't inherit any method.</p>

<dl>
 <dt>{{domxref("SubtleCrypto.encrypt()")}}</dt>
 <dd>Returns a {{jsxref("Promise")}} of the encrypted data corresponding to the clear text, algorithm and key given as parameters.</dd>
 <dt>{{domxref("SubtleCrypto.decrypt()")}}</dt>
 <dd>Returns a {{jsxref("Promise")}} of the clear data corresponding to the encrypted text, algorithm and key given as parameters.</dd>
 <dt>{{domxref("SubtleCrypto.sign()")}}</dt>
 <dd>Returns a {{jsxref("Promise")}} of the signature corresponding to the text, algorithm and key given as parameters.</dd>
 <dt>{{domxref("SubtleCrypto.verify()")}}</dt>
 <dd>Returns a {{jsxref("Promise")}} of a {{jsxref("Boolean")}} value indicating if the signature given as parameter matches the text, algorithm and key also given as parameters.</dd>
 <dt>{{domxref("SubtleCrypto.digest()")}}</dt>
 <dd>Returns a {{jsxref("Promise")}} of a digest generated from the algorithm and text given as parameters.</dd>
 <dt>{{domxref("SubtleCrypto.generateKey()")}}</dt>
 <dd>Returns a {{jsxref("Promise")}} of a newly generated {{domxref("CryptoKey")}}, for symmetrical algorithms, or a {{domxref("CryptoKeyPair")}}, containing two newly generated keys, for asymmetrical algorithm, that matches the algorithm, the usages and the extractability given as parameters.</dd>
 <dt>{{domxref("SubtleCrypto.deriveKey()")}}</dt>
 <dd>Returns a {{jsxref("Promise")}} of a newly generated {{domxref("CryptoKey")}} derived from a master key and a specific algorithm given as parameters.</dd>
 <dt>{{domxref("SubtleCrypto.deriveBits()")}}</dt>
 <dd>Returns a {{jsxref("Promise")}} of a newly generated buffer of pseudo-random bits derived from a master key and a specific algorithm given as parameters.</dd>
 <dt>{{domxref("SubtleCrypto.importKey()")}}</dt>
 <dd>Returns a {{jsxref("Promise")}} of a {{domxref("CryptoKey")}} corresponding to the format, the algorithm, the raw key data, the usages and the extractability given as parameters.</dd>
 <dt>{{domxref("SubtleCrypto.exportKey()")}}</dt>
 <dd>Returns a {{jsxref("Promise")}} of a buffer containing the key in the format requested.</dd>
 <dt>{{domxref("SubtleCrypto.wrapKey()")}}</dt>
 <dd>Returns a {{jsxref("Promise")}} of a wrapped symmetric key for usage (transfer, storage) in insecure environments. The wrapped buffer returned is in the format given in parameters, and contains the key wrapped by the given wrapping key with the given algorithm.</dd>
 <dt>{{domxref("SubtleCrypto.unwrapKey()")}}</dt>
 <dd>Returns a {{jsxref("Promise")}} of a {{domxref("CryptoKey")}} corresponding to the wrapped key given in parameter.</dd>
</dl>

<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', '#subtlecrypto-interface', 'SubtleCrypto') }}</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>Edge</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>{{ CompatVersionUnknown() }}</td>
   <td>{{ CompatGeckoDesktop(34) }}</td>
   <td>{{ CompatNo() }}</td>
   <td>{{ CompatUnknown() }}</td>
   <td>8</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>37</td>
   <td>{{ CompatChrome(37) }}</td>
   <td>{{ CompatGeckoMobile(34) }}</td>
   <td>{{ CompatNo }}</td>
   <td>{{ CompatUnknown() }}</td>
   <td>8</td>
  </tr>
 </tbody>
</table>
</div>

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

<ul>
 <li>{{domxref("Crypto")}} and {{domxref("Crypto.subtle")}}.</li>
</ul>
Revert to this revision