W3cubDocs

/DOM

SubtleCrypto.sign

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

Syntax

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

Parameters

  • algorithm specifies the signature algorithm to use and its parameters:
    • To use RSASSA-PKCS1-v1_5, pass the string "RSASSA-PKCS1-v1_5" or an object of the form { "name": "RSASSA-PKCS1-v1_5" }.
    • To use RSA-PSS, pass a RsaPssParams object.
    • To use ECDSA, pass a EcdsaParams object.
    • To use HMAC, pass the string "HMAC" or an object of the form { "name": "HMAC" }.
  • key is a CryptoKey containing the private key to be used for signing.
  • text2sign is a ArrayBuffer or an ArrayBufferView containing the data to be signed.

Return value

  • signature is a Promise that returns the signature on success.

Exceptions

The promise is rejected when the following exception is encountered:

  • 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
Web Cryptography API
The definition of 'SubtleCrypto.sign()' in that specification.
Recommendation Initial definition.

Browser compatibilityUpdate compatibility data on GitHub

Desktop
Chrome Edge Firefox Internet Explorer Opera Safari
Basic support 37 12
12
Not supported: RSA-PSS, ECDSA.
34
34
32 — 34
Disabled
Disabled From version 32 until version 34 (exclusive): this feature is behind the dom.webcrypto.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
11
11
Returns CryptoOperation instead of Promise
24 7
Mobile
Android webview Chrome for Android Edge Mobile Firefox for Android Opera for Android iOS Safari Samsung Internet
Basic support 37 37 12 34
34
32 — 34
Disabled
Disabled From version 32 until version 34 (exclusive): this feature is behind the dom.webcrypto.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
24 7 6.0

See also

© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/sign