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(algo, key, text2sign);

Parameters

  • 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.

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 compatibility

FeatureChromeEdgeFirefoxInternet ExplorerOperaSafari
Basic support37123411248
FeatureAndroid webviewChrome for AndroidEdge mobileFirefox for AndroidOpera AndroidiOS SafariSamsung Internet
Basic support5353 ?3437 ?6.0

See also

Document Tags and Contributors

Contributors to this page: fscholz, Dans24, abbycar, groovecoder, dskloet, teoli
Last updated by: fscholz,