{"id":18601548,"url":"https://github.com/peculiarventures/webcrypto-liner","last_synced_at":"2025-04-04T07:08:30.597Z","repository":{"id":11001735,"uuid":"67954380","full_name":"PeculiarVentures/webcrypto-liner","owner":"PeculiarVentures","description":"webcrypto-liner is a polyfill that let's down-level User Agents (like IE/Edge) use libraries that depend on WebCrypto. (Keywords: Javascript, WebCrypto, Shim, Polyfill)","archived":false,"fork":false,"pushed_at":"2024-08-25T08:15:04.000Z","size":1370,"stargazers_count":150,"open_issues_count":39,"forks_count":26,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-03-27T21:39:08.451Z","etag":null,"topics":["cryptography","cryptohraphy","ecc","javascript","node-webcrypto-ossl","polyfill","rsa","secp256k1","sha","shim","webcrypto","webcrypto-liner"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PeculiarVentures.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-09-11T21:06:41.000Z","updated_at":"2025-03-09T17:17:29.000Z","dependencies_parsed_at":"2024-10-30T21:42:33.130Z","dependency_job_id":null,"html_url":"https://github.com/PeculiarVentures/webcrypto-liner","commit_stats":{"total_commits":341,"total_committers":15,"mean_commits":"22.733333333333334","dds":"0.29325513196480935","last_synced_commit":"456c644b831338a7bd480d1cd58e9f3fce513d4c"},"previous_names":[],"tags_count":36,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PeculiarVentures%2Fwebcrypto-liner","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PeculiarVentures%2Fwebcrypto-liner/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PeculiarVentures%2Fwebcrypto-liner/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PeculiarVentures%2Fwebcrypto-liner/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PeculiarVentures","download_url":"https://codeload.github.com/PeculiarVentures/webcrypto-liner/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247135144,"owners_count":20889421,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cryptography","cryptohraphy","ecc","javascript","node-webcrypto-ossl","polyfill","rsa","secp256k1","sha","shim","webcrypto","webcrypto-liner"],"created_at":"2024-11-07T02:08:43.369Z","updated_at":"2025-04-04T07:08:30.575Z","avatar_url":"https://github.com/PeculiarVentures.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# webcrypto-liner\n[![license](https://img.shields.io/badge/license-MIT-green.svg?style=flat)](https://raw.githubusercontent.com/PeculiarVentures/webcrypto-liner/master/LICENSE)\n[![npm version](https://badge.fury.io/js/webcrypto-liner.svg)](https://badge.fury.io/js/webcrypto-liner)\n![test](https://github.com/PeculiarVentures/webcrypto-liner/workflows/test/badge.svg)\n\n[![NPM](https://nodei.co/npm/webcrypto-liner.png)](https://nodei.co/npm/webcrypto-liner/)\n\n\nA polyfill for WebCrypto that \"smooths out\" the rough-edges in existing User Agent implementations.\n\nThough WebCrypto is well [supported across browsers](http://caniuse.com/cryptography), several browsers still have prefixed and buggy implementations. Additionally, they do not always support the same algorithms, for example, Edge does not support SHA1 or ECC while both Firefox and Chrome do. \n\n**NOTE**: If you are not familiar with how to use the various capabilities of WebCrypto see [this great example  page](https://github.com/diafygi/webcrypto-examples).\n\n## Browsers support\n\n| [\u003cimg src=\"https://raw.githubusercontent.com/alrra/browser-logos/master/src/edge/edge_48x48.png\" alt=\"IE / Edge\" width=\"24px\" height=\"24px\" /\u003e](http://godban.github.io/browsers-support-badges/)\u003c/br\u003e Edge | [\u003cimg src=\"https://raw.githubusercontent.com/alrra/browser-logos/master/src/firefox/firefox_48x48.png\" alt=\"Firefox\" width=\"24px\" height=\"24px\" /\u003e](http://godban.github.io/browsers-support-badges/)\u003c/br\u003eFirefox | [\u003cimg src=\"https://raw.githubusercontent.com/alrra/browser-logos/master/src/chrome/chrome_48x48.png\" alt=\"Chrome\" width=\"24px\" height=\"24px\" /\u003e](http://godban.github.io/browsers-support-badges/)\u003c/br\u003eChrome | [\u003cimg src=\"https://raw.githubusercontent.com/alrra/browser-logos/master/src/safari/safari_48x48.png\" alt=\"Safari\" width=\"24px\" height=\"24px\" /\u003e](http://godban.github.io/browsers-support-badges/)\u003c/br\u003eSafari |\n| --------- | --------- | --------- | --------- |\n| last 2 versions| last 2 versions| last 2 versions| last 2 versions| last 2 versions| last 2 versions| last 2 versions\n\n## Information\n\n`webcrypto-liner` is a wrapper for WebCrypto designed to address these issues, at the same time it was designed to be modular so that it can also be used for testing the addition of new algorithms to WebCrypto in the future.\n\nIntentionally `webcrypto-liner` does not implement any cryptography though it does consume libraries that do. We strongly recommend you read \"[What’s wrong with in-browser cryptography?](https://tonyarcieri.com/whats-wrong-with-webcrypto)\" before using this library.\n\nThe libraries `webcrypto-liner` relies on include:\n\n| Package                                                    | Description                                                                            | Size   | Optional    |\n|------------------------------------------------------------|----------------------------------------------------------------------------------------|--------|-------------|\n| [asmcrypto.js](https://github.com/vibornoff/asmcrypto.js/) | A [performant](https://medium.com/@encryb/comparing-performance-of-javascript-cryptography-libraries-42fb138116f3) JavaScript implementation of popular cryptographic utilities with performance in mind. | 131\u0026#160;KB | Yes |\n| [elliptic](https://github.com/indutny/elliptic)            | Fast Elliptic Curve Cryptography in plain javascript                                   | 130\u0026#160;KB | Yes  |\n| [webcrypto-core](https://github.com/PeculiarVentures/webcrypto-core)            | A input validation layer for WebCrypto polyfills \u003csup\u003e1\u003c/sup\u003e    | 25\u0026#160;KB | No  |\n\n\u003csup\u003e1 This library is compiled into webcrypto-liner.\u003c/sup\u003e\n\n`webcrypto-liner` will always try to use a native implementation of webcrypto, or a prefixed version of webcrypto, before it falls back to a Javascript implementation of a given algorithm. We have no control over the corresponding implementation and what it does, for example, it may not use `window.crypto.getRandomValues` even if it is available and the mechanism it uses to gather randomness may be both insecure and weak.\n\nWe have done no security review or take a position on the security of these third-party libraries. **YOU HAVE BEEN WARNED**.\n\nTo keep `webcrypto-liner` as small as possible (right now it is ~11kb without dependencies) it was designed to be modular, so if you do not need ECC support, do not include `elliptic` as a dependency and it will not be loaded.\n\nIf you do not load any of the dependencies that provide cryptographic implementations `webcrypto-liner` will work as an interoperability layer, very similar to [webcrypto-shim](https://github.com/vibornoff/webcrypto-shim).\n\n`webcrypto-liner` supports the following algorithms and key lengths:\n\n| Capability                | Details                                       |\n|---------------------------|-----------------------------------------------|\n| Encryption/Decryption     | RSA-OAEP, [DES-CBC](https://github.com/PeculiarVentures/webcrypto-docs/blob/master/DES_CBC.md)\u003csup\u003e1\u003c/sup\u003e, [DES-EDE3-CBC](https://github.com/PeculiarVentures/webcrypto-docs/blob/master/DES_EDE3_CBC.md)\u003csup\u003e1\u003c/sup\u003e, AES-ECB \u003csup\u003e1\u003c/sup\u003e, AES-CBC, AES-ECB and AES-GCM |\n| Sign/Verify               | RSA-PSS, RSASSA_PKCS1-v1_5 and ECDSA          |\n| Hash                      | SHA-1, and SHA-256, SHA-512                   |\n| Derive Key/Bits           | ECDH, PBKDF2                                  |\n| Keywrap                   | AES-GCM, AES-CBC, AES-ECB \u003csup\u003e1\u003c/sup\u003e, [DES-CBC](https://github.com/PeculiarVentures/webcrypto-docs/blob/master/DES_CBC.md)\u003csup\u003e1\u003c/sup\u003e, [DES-EDE3-CBC](https://github.com/PeculiarVentures/webcrypto-docs/blob/master/DES_EDE3_CBC.md)\u003csup\u003e1\u003c/sup\u003e        |\n| ECC Curves                | P-256, P-384, P-521, and [K-256](https://github.com/PeculiarVentures/webcrypto-core/blob/master/spec/EC_K_256.md)\u003csup\u003e2\u003c/sup\u003e (secp256k1)    |\n| RSA Key Lengths           | 1024, 2048, 3072, and 4096                    |\n| AES Key Lengths           | 128, 192 and 256                              |\n\n\u003csup\u003e1\u003c/sup\u003e Mechanism is not defined by the WebCrypto specifications. Use of mechanism in a safe way is hard, it was added for the purpose of enabling interoperability with an existing system. We recommend against its use unless needed for interoperability.\n\n\u003csup\u003e2\u003c/sup\u003e K-256 (secp256k1) curve is not defined by the WebCrypto specifications.\n\nYou can see the `webcrypto-liner` in use in the [`pv-webcrypto-tests` page](https://peculiarventures.github.io/pv-webcrypto-tests/).\n\n## Using\n\n```html\n\u003chead\u003e\n  \u003c!-- Crypto providers are optional --\u003e\n  \u003cscript src=\"https://cdnjs.cloudflare.com/ajax/libs/babel-polyfill/7.7.0/polyfill.min.js\"\u003e\u003c/script\u003e\n  \u003cscript src=\"https://cdnjs.cloudflare.com/ajax/libs/asmCrypto/2.3.2/asmcrypto.all.es5.min.js\"\u003e\u003c/script\u003e\n  \u003cscript src=\"https://cdn.rawgit.com/indutny/elliptic/master/dist/elliptic.min.js\"\u003e\u003c/script\u003e\n  \u003c!-- Crypto --\u003e\n  \u003cscript src=\"webcrypto-liner.shim.js\"\u003e\u003c/script\u003e\n\u003c/head\u003e\n\u003cbody\u003e\n  \u003cscript\u003e \n    crypto.subtle.generateKey({name: \"AES-GCM\", length: 192}, true, [\"encrypt\", \"decrypt\"])\n      .then(function(key){\n        return crypto.subtle.encrypt({\n            name: \"AES-GCM\", \n            iv: new Uint8Array([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]),\n            tagLength: 128\n          }, key, new Uint8Array([1,2,3,4,5]))\n      })\n      .then(function(enc){\n        console.log(new Uint8Array(enc));\n      })\n      .catch(function(err){\n        console.log(err.message); // Chrome throws: 192-bit AES keys are not supported\n      })\n  \u003c/script\u003e\n\u003c/body\u003e\n```\n\n\n## Dependencies\ntypescript\n```\nnpm install typescript --global\n```\n\n## Installation\nThe module has been designed to be useful in ES6 and ES5 projects. The default is ES5 with commonjs, to install and build you would run:\n\n```\nnpm install\nnpm run build\n```\n\n## FAQ\n- **Do I need to use a promise library?** - No, not if your browser supports promises.\n- **Do I need to include asmcrypto.js?** No, not unless you want to use the algorithms it exposes.\n- **Do I need to include elliptic.js?** No, not unless you want to use the algorithms it exposes.\n- **How are random numbers generated?** We use two libraries for crypto operations in Javascript, [asymcrypto](https://github.com/vibornoff/asmcrypto.js/blob/bffc0674c7756dff16c69c5665b9eea2e0409736/src/random/globals.js#L4) and [ellipticjs](https://github.com/indutny/elliptic/blob/cbace4683a4a548dc0306ef36756151a20299cd5/dist/elliptic.js#L7464) both rely on [window.crypto.getRandomValues](http://caniuse.com/#feat=getrandomvalues) where available. `asymcrypto` also has a fallback mechanism where it generates its own random numbers if not present.\n- **How big is the total package?** Right now, if you include all optional dependencies (minfied) the package is ~300 KB, if you include only ECC or only RSA support that is lowered to about 180 KB. Additionally you will see GZIP compression provide about 30% savings above and beyond that. If you use `webcrypto-liner` as just an interopability shim and do not use any of the optional third-party libraries it will be under 44 KB in size.\n- **Will it work in Node?** No. It is compiles to pure Javascript but uses the `window` object so it wont work in Node at this time. With some minor changes it should also be able to work in Node also but you really should be using [node-webcrypto-ossl](https://github.com/PeculiarVentures/node-webcrypto-ossl) on Node instead.\n\n## Related\n - [@peculiar/webcrypto](https://github.com/PeculiarVentures/webcrypto)\n - [node-webcrypto-p11](https://github.com/PeculiarVentures/node-webcrypto-p11)\n - [node-webcrypto-ossl](https://github.com/PeculiarVentures/node-webcrypto-ossl)\n - [pv-webcrypto-tests](https://peculiarventures.github.io/pv-webcrypto-tests)\n - [webcrypto-core](https://peculiarventures.github.io/webcrypto-core)\n - [WebCrypto Examples](https://github.com/diafygi/webcrypto-examples)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeculiarventures%2Fwebcrypto-liner","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpeculiarventures%2Fwebcrypto-liner","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeculiarventures%2Fwebcrypto-liner/lists"}