Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Microsoft Playwright CryptoUtils

From Leeroopedia

Template:Implementation Page

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 GUID
  • calculateSha1() -- computes SHA1 hash of a buffer or string
  • Self-signed certificate generation -- creates TLS certificates for testing using a pure-JavaScript DER encoder. The DER class encodes ASN.1 structures (sequences, integers, object identifiers, bit strings, etc.) and generateSelfSignedCertificate() 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

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment