{"id":26121776,"url":"https://github.com/ipfs-shipyard/js-crypto-key-composer","last_synced_at":"2026-02-25T20:03:25.217Z","repository":{"id":34684953,"uuid":"177515833","full_name":"ipfs-shipyard/js-crypto-key-composer","owner":"ipfs-shipyard","description":"A library to parse crypto keys in different types and formats","archived":false,"fork":false,"pushed_at":"2025-05-01T08:39:40.000Z","size":975,"stargazers_count":13,"open_issues_count":25,"forks_count":4,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-09-15T00:04:16.211Z","etag":null,"topics":["crypto-keys","ed25591","jwe","jwt","pem","pkcs1","pkcs8","raw","rsa","secp256k1"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/ipfs-shipyard.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2019-03-25T04:45:47.000Z","updated_at":"2025-05-01T07:34:33.000Z","dependencies_parsed_at":"2025-09-15T00:01:57.583Z","dependency_job_id":"5bb7770a-ee13-41d9-bde7-7e19ba0bbdb4","html_url":"https://github.com/ipfs-shipyard/js-crypto-key-composer","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/ipfs-shipyard/js-crypto-key-composer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ipfs-shipyard%2Fjs-crypto-key-composer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ipfs-shipyard%2Fjs-crypto-key-composer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ipfs-shipyard%2Fjs-crypto-key-composer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ipfs-shipyard%2Fjs-crypto-key-composer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ipfs-shipyard","download_url":"https://codeload.github.com/ipfs-shipyard/js-crypto-key-composer/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ipfs-shipyard%2Fjs-crypto-key-composer/sbom","scorecard":{"id":493693,"data":{"date":"2025-08-11","repo":{"name":"github.com/ipfs-shipyard/js-crypto-key-composer","commit":"c74cbc83e158a854bf33fced010df751fc2f5e28"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.4,"checks":[{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Code-Review","score":0,"reason":"Found 1/13 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Token-Permissions","score":10,"reason":"GitHub workflow tokens follow principle of least privilege","details":["Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: third-party GitHubAction not pinned by hash: .github/workflows/generated-pr.yml:14: update your workflow using https://app.stepsecurity.io/secureworkflow/ipfs-shipyard/js-crypto-key-composer/generated-pr.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/stale.yml:14: update your workflow using https://app.stepsecurity.io/secureworkflow/ipfs-shipyard/js-crypto-key-composer/stale.yml/master?enable=pin","Info:   0 out of   2 third-party GitHubAction dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 2 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Vulnerabilities","score":0,"reason":"76 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-968p-4wvh-cqc8","Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92","Warn: Project is vulnerable to: GHSA-6chw-6frg-f759","Warn: Project is vulnerable to: GHSA-v88g-cgmw-v5xw","Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw","Warn: Project is vulnerable to: GHSA-fwr7-v2mv-hh25","Warn: Project is vulnerable to: GHSA-v6h2-p8h4-qcjw","Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg","Warn: Project is vulnerable to: GHSA-w8qv-6jwh-64r5","Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275","Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c","Warn: Project is vulnerable to: GHSA-w573-4hg7-7wgq","Warn: Project is vulnerable to: GHSA-ff7x-qrg7-qggm","Warn: Project is vulnerable to: GHSA-3gx7-xhv7-5mx3","Warn: Project is vulnerable to: GHSA-fjxv-7rqg-78g4","Warn: Project is vulnerable to: GHSA-8r6j-v8pm-fqw3","Warn: Project is vulnerable to: MAL-2023-462","Warn: Project is vulnerable to: GHSA-w457-6q6x-cgp9","Warn: Project is vulnerable to: GHSA-62gr-4qp9-h98f","Warn: Project is vulnerable to: GHSA-f52g-6jhx-586p","Warn: Project is vulnerable to: GHSA-2cf5-4w76-r9qv","Warn: Project is vulnerable to: GHSA-3cqr-58rm-57f8","Warn: Project is vulnerable to: GHSA-g9r4-xpmj-mj65","Warn: Project is vulnerable to: GHSA-q2c6-c6pm-g3gh","Warn: Project is vulnerable to: GHSA-765h-qjxv-5f44","Warn: Project is vulnerable to: GHSA-f2jv-r9rf-7988","Warn: Project is vulnerable to: GHSA-43f8-2h32-f4cj","Warn: Project is vulnerable to: GHSA-qqgx-2p2h-9c37","Warn: Project is vulnerable to: GHSA-896r-f27r-55mw","Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h","Warn: Project is vulnerable to: GHSA-6c8f-qphg-qjgp","Warn: Project is vulnerable to: GHSA-jf85-cpcp-j695","Warn: Project is vulnerable to: GHSA-p6mc-m468-83gw","Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9","Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm","Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv","Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3","Warn: Project is vulnerable to: GHSA-vh95-rmgr-6w4m","Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h","Warn: Project is vulnerable to: GHSA-fhjf-83wg-r2j9","Warn: Project is vulnerable to: GHSA-92xj-mqp7-vmcj","Warn: Project is vulnerable to: GHSA-wxgw-qj99-44c2","Warn: Project is vulnerable to: GHSA-5rrq-pxf6-6jx5","Warn: Project is vulnerable to: GHSA-8fr3-hfg3-gpgp","Warn: Project is vulnerable to: GHSA-gf8q-jrpm-jvxq","Warn: Project is vulnerable to: GHSA-2r2c-g63r-vccr","Warn: Project is vulnerable to: GHSA-cfm4-qjh2-4765","Warn: Project is vulnerable to: GHSA-x4jg-mjrx-434g","Warn: Project is vulnerable to: GHSA-5fw9-fq32-wv5p","Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9","Warn: Project is vulnerable to: GHSA-6fw4-hr69-g3rv","Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp","Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6","Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw","Warn: Project is vulnerable to: GHSA-4g88-fppr-53pp","Warn: Project is vulnerable to: GHSA-4jqc-8m5r-9rpr","Warn: Project is vulnerable to: GHSA-3f95-r44v-8mrg","Warn: Project is vulnerable to: GHSA-28xr-mwxg-3qc8","Warn: Project is vulnerable to: GHSA-9p95-fxvg-qgq2","Warn: Project is vulnerable to: GHSA-9w5j-4mwv-2wj8","Warn: Project is vulnerable to: GHSA-7xcx-6wjh-7xp2","Warn: Project is vulnerable to: GHSA-3jfq-g458-7qm9","Warn: Project is vulnerable to: GHSA-r628-mhmh-qjhw","Warn: Project is vulnerable to: GHSA-9r2w-394v-53qc","Warn: Project is vulnerable to: GHSA-5955-9wpr-37jh","Warn: Project is vulnerable to: GHSA-qq89-hq3f-393p","Warn: Project is vulnerable to: GHSA-f5x3-32g6-xq36","Warn: Project is vulnerable to: GHSA-52f5-9888-hmc6","Warn: Project is vulnerable to: GHSA-jgrx-mgxx-jf9v","Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3","Warn: Project is vulnerable to: GHSA-7p7h-4mm5-852v","Warn: Project is vulnerable to: GHSA-38fc-wpqx-33j7","Warn: Project is vulnerable to: GHSA-6fc8-4gx4-v693","Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q","Warn: Project is vulnerable to: GHSA-c4w7-xm78-47vh","Warn: Project is vulnerable to: GHSA-p9pc-299p-vxgp"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-19T19:53:15.555Z","repository_id":34684953,"created_at":"2025-08-19T19:53:15.559Z","updated_at":"2025-08-19T19:53:15.559Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29837463,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-25T19:08:47.527Z","status":"ssl_error","status_checked_at":"2026-02-25T18:59:04.705Z","response_time":61,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["crypto-keys","ed25591","jwe","jwt","pem","pkcs1","pkcs8","raw","rsa","secp256k1"],"created_at":"2025-03-10T14:36:31.902Z","updated_at":"2026-02-25T20:03:25.185Z","avatar_url":"https://github.com/ipfs-shipyard.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# crypto-key-composer\n\n[![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Coverage Status][codecov-image]][codecov-url] [![Dependency status][david-dm-image]][david-dm-url] [![Dev Dependency status][david-dm-dev-image]][david-dm-dev-url]\n\n[npm-url]:https://npmjs.org/package/crypto-key-composer\n[downloads-image]:http://img.shields.io/npm/dm/crypto-key-composer.svg\n[npm-image]:http://img.shields.io/npm/v/crypto-key-composer.svg\n[travis-url]:https://travis-ci.org/ipfs-shipyard/js-crypto-key-composer\n[travis-image]:http://img.shields.io/travis/ipfs-shipyard/js-crypto-key-composer/master.svg\n[codecov-url]:https://codecov.io/gh/ipfs-shipyard/js-crypto-key-composer\n[codecov-image]:https://img.shields.io/codecov/c/github/ipfs-shipyard/js-crypto-key-composer/master.svg\n[david-dm-url]:https://david-dm.org/ipfs-shipyard/js-crypto-key-composer\n[david-dm-image]:https://img.shields.io/david/ipfs-shipyard/js-crypto-key-composer.svg\n[david-dm-dev-url]:https://david-dm.org/ipfs-shipyard/js-crypto-key-composer?type=dev\n[david-dm-dev-image]:https://img.shields.io/david/dev/ipfs-shipyard/js-crypto-key-composer.svg\n\nA library to decompose and compose crypto keys of different types and formats.\n\n\n## Installation\n\n```sh\n$ npm install crypto-key-composer\n```\n\nThis library is written in modern JavaScript and is published in both CommonJS and ES module transpiled variants. If you target older browsers please make sure to transpile accordingly.\nMoreover, some of this library's dependencies use the native Node [Buffer](https://nodejs.org/api/buffer.html) module. This means that you must compile your app through a bundler that automatically injects a Buffer compatible implementation for the browser, such as Webpack.\n\n\n## API\n\n- [`decomposePrivateKey(inputKey, [options])`](#decomposeprivatekeyinputkey-options)\n- [`composePrivateKey(decomposedKey, [options])`](#composeprivatekeydecomposedkey-options)\n- [`decomposePublicKey(inputKey, [options])`](#decomposepublickeyinputkey-options)\n- [`composePublicKey(decomposedKey)`](#composepublickeydecomposedkey)\n- [`getKeyTypeFromAlgorithm(keyAlgorithm)`](#getkeytypefromalgorithmkeyalgorithm)\n\n### decomposePrivateKey(inputKey, [options])\n\nParses a private key, extracting information containing its [`format`](#formats), [`keyAlgorithm`](#key-algorithms), [`keyData`](#key-data) and [`encryptionAlgorithm`](#encryption-algorithms).\n\n```js\nimport { decomposePrivateKey } from 'crypto-key-composer';\n\nconst myPrivatePemKey = `\n-----BEGIN RSA PRIVATE KEY-----\nACTUAL KEY BASE64 HERE\n-----END RSA PRIVATE KEY-----\n`\n\nconst myPrivateDecomposedKey = decomposePrivateKey(myPrivatePemKey)\n// {\n//     format: 'pkcs1-pem',\n//     keyAlgorithm: {\n//         id: 'rsa-encryption'\n//     },\n//     keyData: {\n//         modulus: Uint8Array(...),\n//         publicExponent: Uint8Array(...),\n//         privateExponent: Uint8Array(...),\n//         // ...\n//     },\n//     encryptionAlgorithm: null\n// }\n```\n\nThe `inputKey` may be a TypedArray (including Node's Buffer), an ArrayBuffer or a binary string.\n\n\u003e ⚠️ Do not use the `keyAlgorithm.id` to identify the key type. The reason is that several identifiers map to the same key type. As an example, `rsa-encryption`, `sha512-with-rsa-encryption`, `rsa-oaep` and `rsassa-pss` are all RSA keys. Instead, use [`getKeyTypeFromAlgorithm`](#getkeytypefromalgorithmkeyalgorithm) to properly get the key type.\n\n**Available options**:\n\n| name | type | default | description |\n| ---- | ---- | ------- | ----------- |\n| format | string/Array | `['raw-pem', 'pkcs8-pem']` | Limit the parsing to one or more [`formats`](#formats) |\n| password | string | | The password to use to decrypt the key |\n\nMeaningful [errors](src/util/errors.js) with codes are thrown if something went wrong. When `options.format` is an array, this function will attempt to decompose the key for the specified formats, in order and one by one. It will succeed if the key is using one of the formats or fail if it's using another format, throwing an AggregatedError containing a `errors` property with the errors indexed by format.\n\n### composePrivateKey(decomposedKey, [options])\n\nComposes a private key from its parts: [`format`](#formats), [`keyAlgorithm`](#key-algorithms), [`keyData`](#key-data) and [`encryptionAlgorithm`](#encryption-algorithms). This function is the inverse of `decomposePrivateKey`.\n\n```js\nimport { composePrivateKey } from 'crypto-key-composer';\n\nconst myPrivatePemKey = composePrivateKey({\n    format: 'pkcs1-pem',\n    keyAlgorithm: {\n        id: 'rsa-encryption',\n    },\n    keyData: {\n        modulus: Uint8Array(...),\n        publicExponent: Uint8Array(...),\n        privateExponent: Uint8Array(...),\n        // ...\n    }\n});\n```\n\nThe return value depends on the format. PEM based formats return a regular string while DER based formats return a Uint8Array.\n\n**Available options**:\n\n| name | type | default | description |\n| ---- | ---- | ------- | ----------- |\n| password | string | | The password to use to encrypt the key |\n\nMeaningful [errors](src/util/errors.js) with codes are thrown if something went wrong.\n\n### decomposePublicKey(inputKey, [options])\n\nParses a public key, extracting information containing its [`format`](#formats), [`keyAlgorithm`](#key-algorithms) and [`keyData`](#key-data).\n\n```js\nimport { decomposePublicKey } from 'crypto-key-composer';\n\nconst myPublicPemKey = `\n-----BEGIN PUBLIC KEY-----\nACTUAL KEY BASE64 HERE\n-----END PUBLIC KEY-----\n`\n\nconst myDecomposedPublicKey = decomposePublicKey(myPublicPemKey)\n// {\n//     format: 'spki-pem',\n//     keyAlgorithm: {\n//         id: 'rsa-encryption'\n//     },\n//     keyData: {\n//        modulus: Uint8Array(...),\n//        publicExponent: Uint8Array(...)\n//     },\n//     encryptionAlgorithm: null\n// }\n```\n\nThe `inputKey` may be a TypedArray (including Node's Buffer), an ArrayBuffer or a binary string.\n\n\u003e ⚠️ Do not use the `keyAlgorithm.id` to identify the key type. The reason is that several identifiers map to the same key type. As an example, `rsa-encryption`, `rsaes-oaep` and `rsassa-pss` are all RSA keys. Instead, use [`getKeyTypeFromAlgorithm`](#get-key-type-from-algorithm) to properly get the key type.\n\nAvailable options:\n\n| name | type | default | description |\n| ---- | ---- | ------- | ----------- |\n| format | string/Array | `['raw-pem', 'spki-pem']` | Limit the parsing to one or more formats |\n\nMeaningful [errors](src/util/errors.js) with codes are thrown if something went wrong. When `options.format` is an array, this function will attempt to decompose the key for the specified formats, in order and one by one. It will succeed if the key is using one of the formats or fail if it's using another format, throwing an AggregatedError containing a `errors` property with the errors indexed by format.\n\n### composePublicKey(decomposedKey)\n\nComposes a public key from its parts: [`format`](#formats), [`keyAlgorithm`](#key-algorithms) and [`keyData`](#key-data). This function is the inverse of `decomposePublicKey`.\n\n```js\nimport { composePublicKey } from 'crypto-key-composer';\n\nconst myPublicPemKey = composePublicKey({\n    format: 'spki-pem',\n    keyAlgorithm: {\n        id: 'rsa-encryption',\n    },\n    keyData: {\n        modulus: Uint8Array(...),\n        publicExponent: Uint8Array(...)\n    }\n});\n```\n\nThe return value depends on the format. PEM based formats return a regular string while DER based formats return a Uint8Array.\n\nMeaningful [errors](src/util/errors.js) with codes are thrown if something went wrong.\n\n### getKeyTypeFromAlgorithm(keyAlgorithm)\n\nReturns the key type based on the passed key algorithm. The `keyAlgorithm` might be an object or a string.\n\n```js\nimport { getKeyTypeFromAlgorithm } from 'crypto-key-composer';\n\ngetKeyTypeFromAlgorithm({ id: 'rsa-encryption' })  // rsa\ngetKeyTypeFromAlgorithm('rsa-encryption')  // rsa\ngetKeyTypeFromAlgorithm('ed25519')  // ed25519\n```\n\n\n## Supported formats and algorithms\n\n### Formats\n\nBelow you will find the list of supported formats for private and public keys.\n\n\u003cdetails\u003e\u003csummary\u003e\u003cstrong\u003eraw-der (public \u0026 private)\u003c/strong\u003e\u003c/summary\u003e\n\nThe `raw-der` is the DER encoded ASN1 format defined in [RFC 8017](https://tools.ietf.org/html/rfc8017) for RSA keys and in [RFC5915](https://tools.ietf.org/html/rfc5915) for EC keys.\n\nSupported public key algorithms:\n- Just the standard `rsa-encryption` RSA algorithm (or the `rsa` alias)\n\nSupported private key algorithms:\n- Just the standard `rsa-encryption` RSA algorithm (or the `rsa` alias)\n- Just the standard `ec-public-key` EC algorithm (or the `ec` alias)\n\nSupported encryption algorithms: *none*\n\n\u003e ⚠️ It's recommended to use the newer PKCS8 \u0026 SPKI formats for private and public keys respectively because they are able to store more types of keys. Moreover, PKCS8 keys may be encrypted.\n\u003c/details\u003e\n\n\u003cdetails\u003e\u003csummary\u003e\u003cstrong\u003eraw-pem (public \u0026 private)\u003c/strong\u003e\u003c/summary\u003e\n\nThe `raw-pem` is the PEM encoded version of `raw-der` and is defined in [RFC 1421](https://tools.ietf.org/html/rfc1421).\n\nSupported public key algorithms:\n- Just the standard `rsa-encryption` RSA algorithm (or the `rsa` alias)\n\nSupported private key algorithms:\n- Just the standard `rsa-encryption` RSA algorithm (or the `rsa` alias)\n- Just the standard `ec-public-key` RSA algorithm (or the `ec` alias)\n\nSupported encryption algorithms:\n- keyDerivationFunc: `openssl-derive-bytes` (default)\n- encryptionScheme: `aes256-cbc` (default), `aes192-cbc`, `aes128-cbc`, `des-ede3-cbc`, `des-cbc`, `rc2-cbc`\n\n\u003e ⚠️ It's recommended to use the newer PKCS8 \u0026 SPKI formats for private and public keys respectively because they are able to store more types of keys. Moreover, PKCS8 keys have stronger encryption.\n\u003c/details\u003e\n\n\u003cdetails\u003e\u003csummary\u003e\u003cstrong\u003epkcs1-der (private)\u003c/strong\u003e\u003c/summary\u003e\n\nThe `pkcs1-der` is the DER encoded ASN1 format defined in [RFC 8017](https://tools.ietf.org/html/rfc8017). It's a subset of the `raw-der` format, supporting only RSA keys.\n\nSupported private key algorithms:\n- Just the standard `rsa-encryption` RSA algorithm (or the `rsa` alias)\n\nSupported encryption algorithms: *none*\n\n\u003e ⚠️ It's recommended to use the newer PKCS8 format for private keys because it's able to store more types of keys and support encryption.\n\u003c/details\u003e\n\n\u003cdetails\u003e\u003csummary\u003e\u003cstrong\u003epkcs1-pem (private)\u003c/strong\u003e\u003c/summary\u003e\n\nThe `pkcs1-pem` is the PEM encoded version of `pkcs1-der` and is defined in [RFC 1421](https://tools.ietf.org/html/rfc1421). It's a subset of the `raw-pem` format, supporting only RSA keys.\n\nSupported private key algorithms:\n- Just the standard `rsa-encryption` RSA algorithm (or the `rsa` alias)\n\nSupported encryption algorithms:\n- keyDerivationFunc: `openssl-derive-bytes` (default)\n- encryptionScheme: `aes256-cbc` (default), `aes192-cbc`, `aes128-cbc`, `des-ede3-cbc`, `des-cbc`, `rc2-cbc`\n\n\u003e ⚠️ It's recommended to use the newer PKCS8 format for private keys because it's able to store more types of keys and support stronger encryption algorithms.\n\u003c/details\u003e\n\n\u003cdetails\u003e\u003csummary\u003e\u003cstrong\u003epkcs8-der (private)\u003c/strong\u003e\u003c/summary\u003e\n\nThe `pkcs8-der` is the DER encoded ASN1 format defined in [RFC 5208](https://tools.ietf.org/html/rfc5208) and [RFC 5985](https://tools.ietf.org/html/rfc5958).\n\nSupported private key algorithms:\n- RSA keys\n- EC keys\n- ED25519 keys\n\nSupported encryption algorithms ([PKCS#5](https://tools.ietf.org/html/rfc8018)):\n- keyDerivationFunc: `pbkdf2` (default)\n- encryptionScheme: `aes256-cbc` (default), `aes192-cbc`, `aes128-cbc`, `des-ede3-cbc`, `des-cbc`, `rc2-cbc`\n\u003c/details\u003e\n\n\u003cdetails\u003e\u003csummary\u003e\u003cstrong\u003epkcs8-pem (private)\u003c/strong\u003e\u003c/summary\u003e\n\nThe `pkcs8-pem` is the PEM encoded version of `pkcs8-der` and is defined in [RFC 1421](https://tools.ietf.org/html/rfc1421).\n\nSupported private key algorithms:\n- RSA keys\n- EC keys\n- ED25519 keys\n\nSupported encryption algorithms ([PKCS#5](https://tools.ietf.org/html/rfc8018)):\n- keyDerivationFunc: `pbkdf2` (default)\n- encryptionScheme: `aes256-cbc` (default), `aes192-cbc`, `aes128-cbc`, `des-ede3-cbc`, `des-cbc`, `rc2-cbc`\n\u003c/details\u003e\n\n\u003cdetails\u003e\u003csummary\u003e\u003cstrong\u003espki-der (public)\u003c/strong\u003e\u003c/summary\u003e\n\nThe `spki-der` is a format to represent various types of public keys and is defined in [RFC 5280](https://tools.ietf.org/html/rfc5280#page-25).\n\nSupported public key algorithms:\n- RSA keys\n- EC keys\n- ED25519 keys\n\nSupported encryption algorithms: *does not apply*\n\u003c/details\u003e\n\n\u003cdetails\u003e\u003csummary\u003e\u003cstrong\u003espki-pem (public)\u003c/strong\u003e\u003c/summary\u003e\n\nThe `spki-pem` is the PEM encoded version of `spki-der` and is defined in [RFC 1421](https://tools.ietf.org/html/rfc1421).\n\nSupported public key algorithms:\n- RSA keys\n- EC keys\n- ED25519 keys\n\nSupported encryption algorithms: *does not apply*\n\u003c/details\u003e\n\n### Key Algorithms\n\nBelow you will find the list of supported key algorithms. Because the actual supported key algorithms vary from format to format, be sure to also check the [Formats](#formats) section.\n\n\u003cdetails\u003e\u003csummary\u003e\u003cstrong\u003eRSA keys\u003c/strong\u003e\u003c/summary\u003e\n\nThe following RSA key algorithms are supported:\n- `rsa-encryption`\n- `md2-with-rsa-encryption`\n- `md4-with-rsa-encryption`\n- `md5-with-rsa-encryption`\n- `sha1-with-rsa-encryption`\n- `sha224-with-rsa-encryption`\n- `sha256-with-rsa-encryption`\n- `sha384-with-rsa-encryption`\n- `sha512-with-rsa-encryption`\n- `sha512-224-with-rsa-encryption`\n- `sha512-256-with-rsa-encryption`\n\n\u003e ⚠️ At the moment, `rsaes-oaep` and `rsassa-pss` are not yet supported (see [issue #4](https://github.com/ipfs-shipyard/js-crypto-key-composer/issues/4)).\n\nAll of them are expressed like so:\n\n```js\n{\n    keyAlgorithm: {\n        id: 'rsa-encryption'\n    }\n}\n```\n\nBecause they have no parameters, the example above may also be expressed like so:\n\n```js\n{\n    keyAlgorithm: 'rsa-encryption'\n}\n```\n\nYou may use the `rsa` alias in the key algorithm id, which maps to `rsa-encryption`.\n\u003c/details\u003e\n\n\u003cdetails\u003e\u003csummary\u003e\u003cstrong\u003eEC keys\u003c/strong\u003e\u003c/summary\u003e\n\nThe following EC (elliptic curve) algorithms are supported:\n\n- `ec-public-key`\n- `ec-dh`\n- `ec-mqv`\n\nOnly named curves may be used. The following curves are supported:\n\n-  `sect163k1`\n-  `sect163r1`\n-  `sect239k1`\n-  `sect113r1`\n-  `sect113r2`\n-  `secp112r1`\n-  `secp112r2`\n-  `secp160r1`\n-  `secp160k1`\n-  `secp256k1`\n-  `sect163r2`\n-  `sect283k1`\n-  `sect283r1`\n-  `sect131r1`\n-  `sect131r2`\n-  `sect193r1`\n-  `sect193r2`\n-  `sect233k1`\n-  `sect233r1`\n-  `secp128r1`\n-  `secp128r2`\n-  `secp160r2`\n-  `secp192k1`\n-  `secp224k1`\n-  `secp224r1`\n-  `secp384r1`\n-  `secp521r1`\n-  `sect409k1`\n-  `sect409r1`\n-  `sect571k1`\n-  `sect571r1`\n-  `secp192r1`\n-  `secp256r1`\n\nThe combination of the key algorithm and the named curve are expressed like so:\n\n```js\n{\n    keyAlgorithm: {\n        id: 'ec-public-key',\n        namedCurve: 'secp256k1',\n    }\n}\n```\n\nYou may use the `ec` alias in the key algorithm id, which maps to `ec-public-key`.\n\u003c/details\u003e\n\n\u003cdetails\u003e\u003csummary\u003e\u003cstrong\u003eED25519 keys\u003c/strong\u003e\u003c/summary\u003e\n\nED25519 keys just have a single algorithm, `ed25519`, and may be expressed like so:\n\n```js\n{\n    keyAlgorithm: {\n        id: 'ed25519'\n    }\n}\n```\n\nBecause there are no parameters, the example above may also be expressed like so:\n\n```js\n{\n    keyAlgorithm: 'ed25519'\n}\n```\n\u003c/details\u003e\n\n### Key Data\n\nThe key data is the interpreted key contents. Below, you will find the key data structure for each key type.\n\n\u003cdetails\u003e\u003csummary\u003e\u003cstrong\u003eRSA private keys\u003c/strong\u003e\u003c/summary\u003e\n\n```js\n{\n    keyData: {\n        modulus: Uint8Array(/* ... */),\n        publicExponent: Uint8Array(/* ... */),\n        privateExponent: Uint8Array(/* ... */),\n        prime1: Uint8Array(/* ... */),\n        prime2: Uint8Array(/* ... */),\n        exponent1: Uint8Array(/* ... */),\n        exponent2: Uint8Array(/* ... */),\n        coefficient: Uint8Array(/* ... */),\n        // Only defined if number of primes is greater than 2\n        otherPrimeInfos: [\n            {\n                prime: Uint8Array(/* ... */),\n                exponent: Uint8Array(/* ... */),\n                coefficient Uint8Array(/* ... */)\n            }\n        ]\n    }\n}\n```\n\u003c/details\u003e\n\n\u003cdetails\u003e\u003csummary\u003e\u003cstrong\u003eRSA public keys\u003c/strong\u003e\u003c/summary\u003e\n   \n```js\n{\n    keyData: {\n        modulus: Uint8Array(/* ... */),\n        publicExponent: Uint8Array(/* ... */)\n    }\n}\n```\n\u003c/details\u003e\n\n\u003cdetails\u003e\u003csummary\u003e\u003cstrong\u003eEC private keys\u003c/strong\u003e\u003c/summary\u003e\n   \n```js\n{\n    keyData: {\n        d: Uint8Array(/* ... */),\n        x: Uint8Array(/* ... */),\n        y: Uint8Array(/* ... */),\n    }\n}\n```\n\u003c/details\u003e\n\n\u003cdetails\u003e\u003csummary\u003e\u003cstrong\u003eEC public keys\u003c/strong\u003e\u003c/summary\u003e\n   \n```js\n{\n    keyData: {\n        x: Uint8Array(/* ... */),\n        y: Uint8Array(/* ... */),\n    }\n}\n```\n\u003c/details\u003e\n\n\u003cdetails\u003e\u003csummary\u003e\u003cstrong\u003eED25519 private keys\u003c/strong\u003e\u003c/summary\u003e\n   \n```js\n{\n    keyData: {\n        seed: Uint8Array( /* 32 bytes */)\n    }\n}\n```\n\nThe seed is composed of 32 bytes which serves as the basis to derive the 64 bytes private key and the 32 bytes public key. This closely follows what is defined in [RFC 8032](https://tools.ietf.org/html/rfc8032#section-5.1.5).\n\u003c/details\u003e\n\n\u003cdetails\u003e\u003csummary\u003e\u003cstrong\u003eED25519 public keys\u003c/strong\u003e\u003c/summary\u003e\n   \n```js\n{\n    keyData: {\n        bytes: Uint8Array( /* 32 bytes */)\n    }\n}\n```\n\u003c/details\u003e\n\n\n### Encryption Algorithms\n\nThe encryption algorithm only apply for private keys and is composed by two parts: **Key Derivation Function** and the **Encryption Scheme**. Below you will find the supported algorithms for these parts. Because the actual supported encryption algorithms vary from format to format, be sure to also check the [Formats](#formats) section.\n\n#### Key Derivation Function\n\n\u003cdetails\u003e\u003csummary\u003e\u003cstrong\u003eOpenSSL derive bytes\u003c/strong\u003e\u003c/summary\u003e\n   \nThe `openssl-derive-bytes` is used when encrypting PKCS#1 PEM keys and was pionereed by OpenSSL to derive a key from the password.\n\n```js\n{\n    encryptionAlgorithm: {\n        keyDerivationFunc: {\n            id: 'openssl-derive-bytes',\n        }\n        encryptionScheme: ...\n    }\n}\n```\n\nBecause there are no parameters, the example above may also be expressed like so:\n\n```js\n{\n    encryptionAlgorithm: {\n        keyDerivationFunc: 'openssl-derive-bytes',\n        encryptionScheme: ...\n    }\n}\n```\n\u003c/details\u003e\n\n\u003cdetails\u003e\u003csummary\u003e\u003cstrong\u003ePBKDF2\u003c/strong\u003e\u003c/summary\u003e\n   \nThe `pbkdf2` is used when encrypting PKCS#8 keys and is part of PKCS#5 defined by [RFC 8018](https://tools.ietf.org/html/rfc8018).\n\n```js\n{\n    encryptionAlgorithm: {\n        keyDerivationFunc: {\n            id: 'pbkdf2',\n            iterationCount: 10000,  // The number of iterations\n            keyLength: 32, // Automatic, based on the `encryptionScheme`\n            prf: 'hmac-with-sha512'  // The pseudo-random function\n        }\n        encryptionScheme: ...\n    }\n}\n```\n\nThe parameters above are the default ones and may be omited if you don't need to tweak them. In that case, you may express the example above like so:\n\n```js\n{\n    encryptionAlgorithm: {\n        keyDerivationFunc: 'pbkdf2',\n        encryptionScheme: ...\n    }\n}\n```\n\nThe supported `prf` values are `hmac-with-sha512` (default), `hmac-with-sha384`, `hmac-with-sha256` and `hmac-with-sha1`.\n\u003c/details\u003e\n\n#### Encryption Scheme\n\n\u003cdetails\u003e\u003csummary\u003e\u003cstrong\u003eAES\u003c/strong\u003e\u003c/summary\u003e\n   \nThe supported AES algorithms are `aes256-cbc`,  `aes192-cbc` and `aes128-cbc`. Here's an example:\n\n```js\n{\n    encryptionAlgorithm: {\n        keyDerivationFunc: ...,\n        encryptionScheme: {\n            id: 'aes256-cbc',\n            iv: Uint8Array(/* random bytes */)\n        }\n    }\n}\n```\n\nThe parameters may be omited if you don't need to tweak them. In that case, you may express the example above like so:\n\n```js\n{\n    encryptionAlgorithm: {\n        keyDerivationFunc: ...,\n        encryptionScheme: 'aes256-cbc'\n    }\n}\n```\n\u003c/details\u003e\n\n\u003cdetails\u003e\u003csummary\u003e\u003cstrong\u003eDES\u003c/strong\u003e\u003c/summary\u003e\n   \nThe supported DES algorithms are `des-cbc` and `des-ede3-cbc` (triple DES). Here's an example:\n\n```js\n{\n    encryptionAlgorithm: {\n        keyDerivationFunc: ...,\n        encryptionScheme: {\n            id: 'des-ede3-cbc',\n            iv: Uint8Array(/* random bytes */)\n        }\n    }\n}\n```\n\nThe parameters may be omited if you don't need to tweak them. In that case, you may express the example above like so:\n\n```js\n{\n    encryptionAlgorithm: {\n        keyDerivationFunc: ...,\n        encryptionScheme: 'aes256-cbc'\n    }\n}\n```\n\u003c/details\u003e\n\n\u003cdetails\u003e\u003csummary\u003e\u003cstrong\u003eRC2\u003c/strong\u003e\u003c/summary\u003e\n   \nThe supported RC2 algorithm is just `rc2-cbc` with `128` (default), `64` or `40` bits. Here's an example:\n\n```js\n{\n    encryptionAlgorithm: {\n        keyDerivationFunc: ...,\n        encryptionScheme: {\n            id: 'rc2-cbc',\n            iv: Uint8Array(/* random bytes */),\n            bits: 128\n        }\n    }\n}\n```\n\nThe parameters may be omited if you don't need to tweak them. In that case, you may express the example above like so:\n\n```js\n{\n    encryptionAlgorithm: {\n        keyDerivationFunc: ...,\n        encryptionScheme: 'rc2-cbc'\n    }\n}\n```\n\u003c/details\u003e\n\n\n## Tests\n\n```sh\n$ npm test\n$ npm test -- --watch # during development\n```\n\n\n## License\n\nReleased under the [MIT License](http://www.opensource.org/licenses/mit-license.php).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fipfs-shipyard%2Fjs-crypto-key-composer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fipfs-shipyard%2Fjs-crypto-key-composer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fipfs-shipyard%2Fjs-crypto-key-composer/lists"}