The SubtleCrypto.sign() method returns a Promise containing the signature corresponding to the text, algorithm and key given as parameters.
Syntax
var signature = crypto.sign(algo, key, text2sign);
Parameters
algois aDOMStringdefining the signature function to use. Supported values are:HMAC,RSASSA-PKCS1-v1_5, andECDSA.- key is a
CryptoKeycontaining the private key to be used for signing. text2signis aArrayBufferor anArrayBufferViewcontaining the data to be signed.
Return value
signatureis aPromisethat returns the signature on success.
Exceptions
The promise is rejected when the following exception is encountered:
InvalidAccessErrorwhen 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
| Feature | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari |
|---|---|---|---|---|---|---|
| Basic support | 37 | (Yes) | 34 (34) | No support | ? | No support |
| Feature | Android | Chrome for Android | Edge | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
|---|---|---|---|---|---|---|---|
| Basic support | (Yes) | 37 | (Yes) | 34.0 (34) | No support | ? | No support |
See also
CryptoandCrypto.subtle.SubtleCrypto, the interface it belongs to.