crypto
Global crypto object.Methods
Generate cryptographically strong random values.Fills the provided array with random values.
Generate a random UUID (version 4).Returns a string like
"550e8400-e29b-41d4-a716-446655440000".Properties
Interface for advanced cryptographic operations.
SubtleCrypto
Provides low-level cryptographic operations.Digest
Generate a digest (hash) of data.Supported algorithms:
SHA-1: 160-bit SHA-1 hash (not recommended for security)SHA-256: 256-bit SHA-2 hashSHA-384: 384-bit SHA-2 hashSHA-512: 512-bit SHA-2 hashMD5: 128-bit MD5 hash (not recommended for security)
Encryption/Decryption
Encrypt data.Supported algorithms:
AES-CBC: AES in Cipher Block Chaining modeAES-CTR: AES in Counter modeAES-GCM: AES in Galois/Counter modeRSA-OAEP: RSA with OAEP padding
Decrypt data.
Signing/Verification
Generate a digital signature.Supported algorithms:
HMAC: Hash-based Message Authentication CodeRSASSA-PKCS1-v1_5: RSA signature with PKCS#1 v1.5 paddingRSA-PSS: RSA signature with PSS paddingECDSA: Elliptic Curve Digital Signature AlgorithmEd25519: EdDSA signature using Curve25519
Verify a digital signature.
Key management
Generate a new cryptographic key or key pair.
Import a key from external data.Key formats:
raw: Raw key datapkcs8: PKCS#8 private keyspki: SubjectPublicKeyInfo public keyjwk: JSON Web Key
Export a key to external data.
Wrap (encrypt) a key using another key.
Unwrap (decrypt) a key using another key.
Key derivation
Derive bits from a base key.Supported algorithms:
PBKDF2: Password-Based Key Derivation Function 2HKDF: HMAC-based Key Derivation FunctionECDH: Elliptic Curve Diffie-HellmanX25519: Curve25519 Diffie-Hellman
Derive a key from a base key.
CryptoKey
Represents a cryptographic key.Properties
Key type.
Whether the key can be exported.
Algorithm the key is used with.
Operations the key can be used for.
Key usages
Key can be used to encrypt data.
Key can be used to decrypt data.
Key can be used to sign data.
Key can be used to verify signatures.
Key can be used to derive other keys.
Key can be used to derive bits.
Key can be used to wrap other keys.
Key can be used to unwrap other keys.
DigestStream
Streaming hash computation (workerd extension).Promise that resolves to the computed digest when the stream is closed.