Implementation:Microsoft Playwright CryptoUtils
Appearance
Overview
CryptoUtils provides cryptographic utility functions including GUID generation, SHA1 hashing, and self-signed TLS certificate creation using ASN.1/DER encoding.
Description
This module offers:
createGuid()-- generates a random 16-byte hex GUIDcalculateSha1()-- computes SHA1 hash of a buffer or string- Self-signed certificate generation -- creates TLS certificates for testing using a pure-JavaScript DER encoder. The
DERclass encodes ASN.1 structures (sequences, integers, object identifiers, bit strings, etc.) andgenerateSelfSignedCertificate()produces a complete certificate with RSA key pair.
The DER encoder supports base-128 variable-length quantity encoding for OIDs and proper ASN.1 tagging.
Usage
createGuid and calculateSha1 are used throughout the codebase for object identification and content hashing. Certificate generation is used for HTTPS testing.
Code Reference
Source Location
packages/playwright-core/src/server/utils/crypto.ts (197 lines)
Function Signatures
export function createGuid(): string;
export function calculateSha1(buffer: Buffer | string): string;
export function generateSelfSignedCertificate(): { cert: string; key: string };
Import
import { createGuid, calculateSha1, generateSelfSignedCertificate } from './server/utils/crypto';
I/O Contract
createGuid
- Input: none
- Output: 32-character hex string
calculateSha1
- Input:
Buffer | string - Output: 40-character hex SHA1 hash
generateSelfSignedCertificate
- Input: none
- Output:
{ cert: string, key: string }in PEM format
Related Pages
- Microsoft_Playwright_Server_Instrumentation -- Uses createGuid for object IDs
- Microsoft_Playwright_LocalUtils -- Uses calculateSha1 for file hashing
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment