From 92484d49458e7fe5a8551271d5b49947b5d5ea48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Sun, 16 Jan 2022 15:09:15 +0100 Subject: [PATCH] doc: make Web Crypto example spec compliant 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: https://github.com/nodejs/node/pull/41556 Reviewed-By: James M Snell Reviewed-By: Antoine du Hamel Reviewed-By: Luigi Pinca Reviewed-By: Benjamin Gruenbaum Reviewed-By: Filip Skokan Reviewed-By: Colin Ihrig --- doc/api/webcrypto.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/doc/api/webcrypto.md b/doc/api/webcrypto.md index 43290395bc6d2a..8aa0c77a3736ae 100644 --- a/doc/api/webcrypto.md +++ b/doc/api/webcrypto.md @@ -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); })(); ```