How to use the subtle function from crypto

Find comprehensive JavaScript crypto.subtle code examples handpicked from public code repositorys.

-3
-2
-1
// JSDom does not include a full implementation of webcrypto
const crypto = require('crypto').webcrypto;
global.crypto.subtle = crypto.subtle;
fork icon493
star icon0
watch icon151

+ 3 other calls in file

67
68
69
70
71
72
73
74
75

const cryptoKey = await crypto.subtle.importKey(
  'raw', keyBytes, { name: 'HMAC', hash: 'SHA-256' },
  true, ['sign']
);
const sig = await crypto.subtle.sign('HMAC', cryptoKey, messageBytes);

// to lowercase hexits
[...new Uint8Array(sig)].map(b => b.toString(16).padStart(2, '0')).join('');
fork icon52
star icon280
watch icon9

+ 3 other calls in file

3
4
5
6
7
8
9
10
11
12
console.log('in generatePKCE');
const code_verifier = generateRandomString();

const encoder = new TextEncoder();
const data = encoder.encode(code_verifier);
const sha256 = await crypto.subtle.digest('SHA-256', data);

let str = '';
const bytes = new Uint8Array(sha256);
const len = bytes.byteLength;
fork icon0
star icon0
watch icon0