How to use the webcrypto function from crypto

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

-4
-3
const crypto = require('crypto');
global.crypto = crypto.webcrypto;
fork icon22
star icon38
watch icon0

38
39
40
41
42
43
44
45
46
47
notAfter.setUTCFullYear(notAfter.getUTCFullYear() + 10)
const usages = x509.KeyUsageFlags.nonRepudiation |
  x509.KeyUsageFlags.digitalSignature |
  x509.KeyUsageFlags.keyEncipherment |
  x509.KeyUsageFlags.keyAgreement
const keys = await crypto.webcrypto.subtle.generateKey(alg, true, ['sign', 'verify'])
const cert = await x509.X509CertificateGenerator.createSelfSigned({
  serialNumber: number,
  name: `CN=${name}`,
  notBefore: new Date(),
fork icon3
star icon90
watch icon8

3
4
5
6
7
8
9
10
global.TextEncoder = TextEncoder;
const crypto = require('crypto');
Object.defineProperty(global, 'crypto', {
  value: {
    getRandomValues: (arr: any) => crypto.randomBytes(arr.length),
    subtle: crypto.webcrypto.subtle,
  },
});
fork icon10
star icon13
watch icon112

4
5
6
7
8
9
10
11
12
**crypto.webcrypto** 是加密模块内一个内置的加密类应用编程接口,用于获取 Web Crypto API 标准的加密对象。

**语法:**

```js
const crypto.webcrypto
```

**参数:**该属性不接受任何参数。
fork icon0
star icon2
watch icon5

+ 3 other calls in file

37
38
39
40
41
42
43
44
45
46
47
48


} else {
	// Always use node webcrypto if available ( >= 16.0 )
	if(platformCrypto && platformCrypto.webcrypto) {
		console.warn("[FIDO2-LIB] Native crypto is enabled");
		webcrypto = platformCrypto.webcrypto;


	} else {
		// Fallback to @peculiar/webcrypto
		webcrypto = new peculiarCrypto.Crypto();
fork icon0
star icon0
watch icon1