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


var signature = crypto<code>.sign(algo, key, text2sign)</code>;


  • algo is a DOMString defining the signature function to use. Supported values are: HMAC, RSASSA-PKCS1-v1_5, and ECDSA.
  • 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.


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.


Specification Status Comment
Web Cryptography API
The definition of 'SubtleCrypto.sign()' in that specification.
Candidate Recommendation Initial definition.

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 37 34 (34) No support ? No support
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support (Yes) 37 34.0 (34) No support ? No support

See also


© 2016 Mozilla Contributors
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.

API Method Reference Référence SubtleCrypto Web Crypto API