From f041c27ece1ef8b3b28dc087f8bc87565554dde1 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. --- 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 db657a6222d5c5..75dceda7f88a96 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); })(); ```