Skip to content

Commit

Permalink
doc: make Web Crypto example spec compliant
Browse files Browse the repository at this point in the history
subtle.sign is not supposed to support strings, and in most Web Crypto
implementations, it does not. Passing a string as the 'data' argument
only works in Node.js, and users should not rely on that oddity. The
Web Crypto spec requires the data argument to be a BufferSource, i.e.,
an ArrayBuffer or an ArrayBufferView.

PR-URL: nodejs#41556
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
  • Loading branch information
tniessen authored and thedull committed Jan 18, 2022
1 parent f365414 commit cfe612c
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion doc/api/webcrypto.md
Expand Up @@ -19,9 +19,12 @@ const { subtle } = require('crypto').webcrypto;
length: 256
}, true, ['sign', 'verify']);

const enc = new TextEncoder();
const message = enc.encode('I love cupcakes');

const digest = await subtle.sign({
name: 'HMAC'
}, key, 'I love cupcakes');
}, key, message);

})();
```
Expand Down

0 comments on commit cfe612c

Please sign in to comment.