$ show PeculiarVentures/webcrypto
This repository provides a WebCrypto API polyfill for Node.js, implementing the W3C Web Cryptography API using Node's native crypto module. It supports a comprehensive set of algorithms including AES (CBC, CTR, GCM, ECB, KW, CMAC), DES (CBC, EDE3-CBC), RSA (SSA, PSS, OAEP, ES), ECDSA, ECDH, EdDSA, ECDH-ES, Ed25519, X25519, HMAC, PBKDF2, HKDF, SHA-1/256/384/512, SHA3-256/384/512, and SHAKE128/256. The architecture follows a provider pattern where each algorithm is implemented as a separate class extending a base provider from the 'webcrypto-core' library. Key management is handled through internal CryptoKey classes with serialization support for JWK, raw, PKCS8, and SPKI formats. The library is designed as a drop-in replacement for the browser's crypto.subtle API, enabling isomorphic JavaScript cryptography.
The LLM identified 2 files worth highlighting for reuse:
Implements AES-CMAC (RFC 4493) from scratch using Node.js crypto for the underlying AES block cipher. The implementation includes subkey generation, message padding, and the CMAC algorithm itself. It is self-contained, with no dependencies on internal modules beyond the key storage mechanism, and could be extracted into a standalone library for AES-CMAC computation.
Implements RSA-OAEP encryption and decryption with custom MGF1 mask generation function. This is necessary because Node.js's built-in RSA-OAEP does not support custom labels. The implementation handles key size calculation, label hashing, and the OAEP padding scheme manually. It demonstrates a non-trivial cryptographic protocol implementation that could be reused in other projects requiring custom OAEP parameters.