webcrypto.dev-examples

Overview

@peculiar/webcrypto is a WebCrypto polyfill based on the NodeJS native crypto implementation that adds support for several cryptographic algorithms not included in the WebCrypto standard, enabling interoperability with existing systems that use those algorithms.

npm npm (scoped)

Samples

Standard WebCrypto mechanisms

Sample Description
AES-CBC key generation and data encryption Demonstrates how to perform AES encryption and decryption.
Create SHA message digests Demonstrates how to compute message digests using SHA-1, SHA-256, SHA-384, and SHA-512.
RSASSA-PKCS1-v1_5 key generation and signing Demonstrates how to generate RSA key pairs then signs and verifies.
RSA key generation and secret key wrapping Demonstrates how to generate RSA and AES keys, wrap and unwrap a secret key, and export a public key.
ECDSA key generation and signing Demonstrates how to generate and export a public key, sign data with a private key, and verify the signature using Elliptic Curve Digital Signature Algorithm (ECDSA) with SHA-256.
ECDH key generation and key deriving Demonstrates how to do key agreement based on Elliptic Curve Diffie-Hellman (ECDH) for secure key exchange between two parties.

Non-Standard WebCrypto mechanisms

Sample Description
Ed25519 Key Generation and Data Signing Demonstrates how to generate an Ed25519 key pair and use it to sign data
X25519 Key Generation and Key Derivation Demonstrates how to generate an X25519 key pair and use it to derive a shared secret
RSAES-PKCS1-v1_5 Key Generation and Secret Key Wrapping Demonstrates how to generate an RSAES-PKCS1-v1_5 key pair and use it to wrap and unwrap a secret key
AES-ECB Key Generation and Data Encryption Demonstrates how to generate an AES-ECB key and use it to encrypt and decrypt data