The `webcrypto-shim` package provides a polyfill for the W3C Web Cryptography API, specifically targeting older browser environments that either lacked support or had prefixed and buggy implementations. Its primary purpose was to enable core Web Crypto functionality in browsers like Internet Explorer 11, Mobile Internet Explorer 11, and Safari versions 8-10 (including iOS Safari 8-10). The shim addresses deficiencies such as the absence of a `Promise` implementation in IE11, which required an external polyfill like `promiz.js`. The package's last stable version, 0.1.7, was released many years ago, and it is no longer actively maintained for modern browser environments, which universally support the Web Crypto API natively. It offered implementations for algorithms including SHA-256/384 for `digest`, HMAC, AES-CBC, AES-KW, RSASSA-PKCS1-v1_5, and RSA-OAEP for operations such as `sign`, `verify`, `encrypt`, `decrypt`, `generateKey`, `importKey`, `exportKey`, `wrapKey`, and `unwrapKey`.
npm install webcrypto-shimVerified import paths — ran on the pinned version, not inferred.
This code snippet demonstrates how to check for and utilize the `window.crypto.subtle` API, potentially provided by the `webcrypto-shim`, to perform an HMAC-SHA256 key generation, signing, and verification operation within a legacy browser environment that requires the shim.
Avoid using `deriveKey` or `deriveBits` if compatibility with IE11 or older Safari versions is required. Implement alternative key derivation logic if necessary.
Always ensure that input data provided to cryptographic operations is non-empty when targeting IE11.
Include a Promise/A+-compatible polyfill script (e.g., `<script src="bower_components/promiz/promiz.js"></script>`) in your HTML before the `webcrypto-shim.js` script.
When performing key wrapping or unwrapping with RSA-OAEP using this shim, explicitly specify and use the 'jwk' format for keys.
Load a Promise polyfill (e.g., `promiz.js`) via a `<script>` tag before the `webcrypto-shim.js` script in your HTML.
Ensure all input data provided to `window.crypto.subtle` methods (e.g., `digest`, `sign`, `encrypt`) is non-empty when targeting IE11.
Avoid using `deriveKey` or `deriveBits` if support for IE11 or older Safari versions is critical for your application.