{{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
- 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
, andECDSA
.text2sign
is a {{jsxref("ArrayBuffer")}} or an {{jsxref("ArrayBufferView")}} containing the data to be signed.
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.