{"_id":"@arve.knudsen/libp2p-crypto","_rev":"2-7d969d06c12576833cc2d93feef1b86f","name":"@arve.knudsen/libp2p-crypto","dist-tags":{"latest":"0.16.3"},"versions":{"0.16.2":{"name":"@arve.knudsen/libp2p-crypto","version":"0.16.2","description":"Crypto primitives for libp2p","main":"src/index.js","leadMaintainer":"Arve Knudsen <arve.knudsen@gmail.com>","browser":{"./src/hmac/index.js":"./src/hmac/index-browser.js","./src/keys/ecdh.js":"./src/keys/ecdh-browser.js","./src/aes/ciphers.js":"./src/aes/ciphers-browser.js","./src/keys/rsa.js":"./src/keys/rsa-browser.js"},"scripts":{"lint":"aegir lint","build":"aegir build","build-proto":"pbjs --wrap commonjs --target static-module src/keys/keys.proto > src/keys/keys.proto.js","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser -t webworker","release":"aegir release","release-minor":"aegir release --type minor","release-major":"aegir release --type major","coverage":"aegir coverage --ignore src/keys/keys.proto.js","size":"bundlesize -f dist/index.min.js -s 139kB"},"keywords":["IPFS","libp2p","crypto","rsa"],"license":"MIT","dependencies":{"asmcrypto.js":"^2.3.2","asn1.js":"^5.0.1","async":"^2.6.2","bn.js":"^4.11.8","browserify-aes":"^1.2.0","bs58":"^4.0.1","iso-random-stream":"^1.1.0","keypair":"^1.0.1","@arve.knudsen/libp2p-crypto-secp256k1":"~0.3.0","multihashing-async":"~0.6.0","node-forge":"~0.7.6","pem-jwk":"^2.0.0","protons":"^1.0.1","rsa-pem-to-jwk":"^1.1.3","tweetnacl":"^1.0.1","ursa-optional":"~0.9.10"},"devDependencies":{"aegir":"^18.2.2","benchmark":"^2.1.4","bundlesize":"~0.17.1","chai":"^4.2.0","chai-string":"^1.5.0","dirty-chai":"^2.0.1"},"engines":{"node":">=10.0.0","npm":">=6.0.0"},"repository":{"type":"git","url":"git+https://github.com/aknuds1/js-libp2p-crypto.git"},"bugs":{"url":"https://github.com/aknuds1/js-libp2p-crypto/issues"},"homepage":"https://github.com/aknuds1/js-libp2p-crypto","contributors":[{"name":"Alberto Elias","email":"hi@albertoelias.me"},{"name":"David Dias","email":"daviddias.p@gmail.com"},{"name":"Dmitriy Ryajov","email":"dryajov@gmail.com"},{"name":"Friedel Ziegelmayer","email":"dignifiedquire@gmail.com"},{"name":"Greenkeeper","email":"support@greenkeeper.io"},{"name":"Hugo Dias","email":"hugomrdias@gmail.com"},{"name":"Jack Kleeman","email":"jackkleeman@gmail.com"},{"name":"Jacob Heun","email":"jacobheun@gmail.com"},{"name":"Joao Santos","email":"jrmsantos15@gmail.com"},{"name":"Maciej Krüger","email":"mkg20001@gmail.com"},{"name":"Richard Littauer","email":"richard.littauer@gmail.com"},{"name":"Richard Schneider","email":"makaretu@gmail.com"},{"name":"Tom Swindell","email":"t.swindell@rubyx.co.uk"},{"name":"Vasco Santos","email":"vasco.santos@ua.pt"},{"name":"Victor Bjelkholm","email":"victorbjelkholm@gmail.com"},{"name":"Yusef Napora","email":"yusef@napora.org"},{"name":"greenkeeper[bot]","email":"greenkeeper[bot]@users.noreply.github.com"},{"name":"nikuda","email":"nikuda@gmail.com"}],"gitHead":"684f08bdfc1cca11e76115c86adbf0e061ce0d56","_id":"@arve.knudsen/libp2p-crypto@0.16.2","_nodeVersion":"12.5.0","_npmVersion":"6.10.0","dist":{"integrity":"sha512-ELp27mJDU0C//jyt31xhuonabG0XEad6bb4kfI27uvkjAZHE5APA5D8AN8N4fTi/lPvIgiQvw/WTu0hqSSSgJw==","shasum":"c4c36b4b818fa5ddb7bfc1f442b47336c4ef6318","tarball":"https://registry.npmjs.org/@arve.knudsen/libp2p-crypto/-/libp2p-crypto-0.16.2.tgz","fileCount":29,"unpackedSize":52661,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJdHfB0CRA9TVsSAnZWagAAWmAQAIHTDKQ4jrboD2krRSh9\nMm39JS658nNYOAi4M6UuRh7vUzfUkST4CAesOYvsXyfz3nj+sueK5D+TwSYw\nv48yjT3bBBpiZHRxLs2J+bOTCJ5jzDMvijb5uj59I4hV/+6gXYByUhv4CY3a\nEZ2tbIJYVl1i485J0Efev6+ftrP1pnf7NTJZ1ir0L2gWmTBIgTSwnS4B7KLj\n1nDU9lzYQ+4YjtXYzZjdQR1rmg+yMRNOZK1jgr5d133EyU4JLmWdWaRm1GlL\nUk7dM/tbEVevY3FxjbkjbIqD58Yp0PLblCAKJQtyNGDVw0Im2Numvonh30q9\n+WgZdOX+mrtaO6ox6ntT8cP2s/6nMaRvmKJ5K4P1g4LnP0dQ+SoHhJ2aBY7g\nvBU+r0bEOhY1CFd4SBtMih6wh9DD1xShl5Cm0HLm0fR3iqOPVhgq7cgsXxmg\nzg7Ac5GsI09r79ZNO528Pj7inPjRhPXOf2lQoag3VBAEhiUpVJIyA8vqBG16\n1pUdBvm0NVdDd6AZBgRUdcJtNyNJwAIk8lVfOC3muOwHsIUjRz034gYFnknU\nJpJ0ui2nRMsXjIT4EyMNuAikPerQBc9iBsc0kAWh18UZKk1xAScKAzNKB8Fu\nHgb5sQ2Vsm/EuWfQpxEeaFfCyZipWT0x4+uRqAF7hwFv+Jfvugt+3bLUgfO6\nF7u/\r\n=H/Hh\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDj1n05e5eZWmcD2gVz+wD8fbu2+mabApJHPPuMcP5urwIgSNuWply2VprKd40ySAs5k15fGz7RdUpc5b2pkgJXwE4="}]},"maintainers":[{"name":"arve.knudsen","email":"arve.knudsen@gmail.com"}],"_npmUser":{"name":"arve.knudsen","email":"arve.knudsen@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/libp2p-crypto_0.16.2_1562243188384_0.34939711005697527"},"_hasShrinkwrap":false},"0.16.3":{"name":"@arve.knudsen/libp2p-crypto","version":"0.16.3","description":"Crypto primitives for libp2p","main":"src/index.js","leadMaintainer":"Arve Knudsen <arve.knudsen@gmail.com>","browser":{"./src/hmac/index.js":"./src/hmac/index-browser.js","./src/keys/ecdh.js":"./src/keys/ecdh-browser.js","./src/aes/ciphers.js":"./src/aes/ciphers-browser.js","./src/keys/rsa.js":"./src/keys/rsa-browser.js"},"scripts":{"lint":"aegir lint","build":"aegir build","build-proto":"pbjs --wrap commonjs --target static-module src/keys/keys.proto > src/keys/keys.proto.js","test":"aegir test","test:node":"aegir test -t node","test:browser":"aegir test -t browser -t webworker","release":"aegir release","release-minor":"aegir release --type minor","release-major":"aegir release --type major","coverage":"aegir coverage --ignore src/keys/keys.proto.js","size":"bundlesize -f dist/index.min.js -s 139kB"},"keywords":["IPFS","libp2p","crypto","rsa"],"license":"MIT","dependencies":{"asmcrypto.js":"^2.3.2","asn1.js":"^5.0.1","async":"^2.6.2","bn.js":"^4.11.8","browserify-aes":"^1.2.0","bs58":"^4.0.1","iso-random-stream":"^1.1.0","keypair":"^1.0.1","libp2p-crypto-secp256k1":"~0.3.1","multihashing-async":"~0.6.0","node-forge":"~0.7.6","pem-jwk":"^2.0.0","protons":"^1.0.1","rsa-pem-to-jwk":"^1.1.3","tweetnacl":"^1.0.1","ursa-optional":"~0.9.10"},"devDependencies":{"aegir":"^18.2.2","benchmark":"^2.1.4","bundlesize":"~0.17.1","chai":"^4.2.0","chai-string":"^1.5.0","dirty-chai":"^2.0.1","sinon":"^7.3.2"},"engines":{"node":">=10.0.0","npm":">=6.0.0"},"repository":{"type":"git","url":"git+https://github.com/aknuds1/js-libp2p-crypto.git"},"bugs":{"url":"https://github.com/aknuds1/js-libp2p-crypto/issues"},"homepage":"https://github.com/aknuds1/js-libp2p-crypto","contributors":[{"name":"Alberto Elias","email":"hi@albertoelias.me"},{"name":"David Dias","email":"daviddias.p@gmail.com"},{"name":"Dmitriy Ryajov","email":"dryajov@gmail.com"},{"name":"Friedel Ziegelmayer","email":"dignifiedquire@gmail.com"},{"name":"Greenkeeper","email":"support@greenkeeper.io"},{"name":"Hugo Dias","email":"hugomrdias@gmail.com"},{"name":"Jack Kleeman","email":"jackkleeman@gmail.com"},{"name":"Jacob Heun","email":"jacobheun@gmail.com"},{"name":"Joao Santos","email":"jrmsantos15@gmail.com"},{"name":"Maciej Krüger","email":"mkg20001@gmail.com"},{"name":"Richard Littauer","email":"richard.littauer@gmail.com"},{"name":"Richard Schneider","email":"makaretu@gmail.com"},{"name":"Tom Swindell","email":"t.swindell@rubyx.co.uk"},{"name":"Vasco Santos","email":"vasco.santos@ua.pt"},{"name":"Victor Bjelkholm","email":"victorbjelkholm@gmail.com"},{"name":"Yusef Napora","email":"yusef@napora.org"},{"name":"greenkeeper[bot]","email":"greenkeeper[bot]@users.noreply.github.com"},{"name":"nikuda","email":"nikuda@gmail.com"}],"gitHead":"3fe4de3865dbe9dd6a9da75c9594f968a10e4640","_id":"@arve.knudsen/libp2p-crypto@0.16.3","_nodeVersion":"12.6.0","_npmVersion":"6.10.0","dist":{"integrity":"sha512-1qZfcxLexXo7sb9vnXagehqZ1U+7azNSlo6waT46SUmssvZrYsOe5PPdnpkzJr8qz2vNilzm2KuDD/aX1HNQ4A==","shasum":"f4860ddd9b9439c9a4af1e52d3358d5289453358","tarball":"https://registry.npmjs.org/@arve.knudsen/libp2p-crypto/-/libp2p-crypto-0.16.3.tgz","fileCount":29,"unpackedSize":52941,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJdJcefCRA9TVsSAnZWagAA9pQP/1i07cLkk/fYpVD3QBjM\nkM/UN5qXD/CbD6mbPi89nJqBcS8GO8n9/JThftNjKIQMQDggyfColeVKqJ/A\nm0IL9XbxUsL1zezHgAQVPe+AroFKukiWZNWQaAT4PDWl9UA70+xMSyF5obX6\nTS+fu8Fhu8gEgDOxR1QLAxQRH/zSCvpWuuPsRXYW1P7GfyB6/uk4TNRzgJ46\nZ5Ou+qN7jtmNHrRejFWb4yX4j52KJpagTrFaUe1EEQnXqSUpnU18UhsGY1X0\nAS05aiqu5grJTckJE1ts0n5M6BzxaNMlEDXEMmxAahcaN4IaiFyurZEibxrj\nO/WduwfK+L58gyljCJsSKs4eTlYHiyk2v4CUguY8Vgbh31Rax4xE/gPjfpAf\nOou0Y/AyHYtl0LM9lUGoUFk4cKZXh1jwn9R2HlP92kyxgle6lzn691zY7GGl\ncGLWOBUiyWKg0WFmwHBLtOFTtWQotuBfTkEjqzIidvEkK9SBAdTJYSrOYgWG\nVS8NT8hUUX/DZ3X5Wfrr4KxVw2PURxKC7u9Zlkz9XVFTYZ3kQHIlOBSRLTsT\n7kg3cmpYsjU1UITSItw0fUsdUy/cKkHvTAs6ulhQaVQuAi9fQ+tpDvUh8yw+\nMjL8EUn9AxHytxmbt4VZKn2+Ak5QN4b2TwqYaDHl2D0qvqG4F7073m9Y/1Yg\n0b3X\r\n=h6Sj\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIGfNnsiH1FtIx8IIpZnwHlpfEUmpXUOS8mLafDoJuOQ7AiAqCyLEk+Q+Po4vNUq6WXs4x3CP6bo0eUq37FaVtER6rw=="}]},"maintainers":[{"name":"arve.knudsen","email":"arve.knudsen@gmail.com"}],"_npmUser":{"name":"arve.knudsen","email":"arve.knudsen@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/libp2p-crypto_0.16.3_1562757022693_0.23797564365144974"},"_hasShrinkwrap":false}},"time":{"created":"2019-07-04T12:26:28.180Z","0.16.2":"2019-07-04T12:26:28.545Z","modified":"2022-04-04T15:41:15.655Z","0.16.3":"2019-07-10T11:10:22.838Z"},"maintainers":[{"name":"arve.knudsen","email":"arve.knudsen@gmail.com"}],"description":"Crypto primitives for libp2p","homepage":"https://github.com/aknuds1/js-libp2p-crypto","keywords":["IPFS","libp2p","crypto","rsa"],"repository":{"type":"git","url":"git+https://github.com/aknuds1/js-libp2p-crypto.git"},"contributors":[{"name":"Alberto Elias","email":"hi@albertoelias.me"},{"name":"David Dias","email":"daviddias.p@gmail.com"},{"name":"Dmitriy Ryajov","email":"dryajov@gmail.com"},{"name":"Friedel Ziegelmayer","email":"dignifiedquire@gmail.com"},{"name":"Greenkeeper","email":"support@greenkeeper.io"},{"name":"Hugo Dias","email":"hugomrdias@gmail.com"},{"name":"Jack Kleeman","email":"jackkleeman@gmail.com"},{"name":"Jacob Heun","email":"jacobheun@gmail.com"},{"name":"Joao Santos","email":"jrmsantos15@gmail.com"},{"name":"Maciej Krüger","email":"mkg20001@gmail.com"},{"name":"Richard Littauer","email":"richard.littauer@gmail.com"},{"name":"Richard Schneider","email":"makaretu@gmail.com"},{"name":"Tom Swindell","email":"t.swindell@rubyx.co.uk"},{"name":"Vasco Santos","email":"vasco.santos@ua.pt"},{"name":"Victor Bjelkholm","email":"victorbjelkholm@gmail.com"},{"name":"Yusef Napora","email":"yusef@napora.org"},{"name":"greenkeeper[bot]","email":"greenkeeper[bot]@users.noreply.github.com"},{"name":"nikuda","email":"nikuda@gmail.com"}],"bugs":{"url":"https://github.com/aknuds1/js-libp2p-crypto/issues"},"license":"MIT","readme":"# js-libp2p-crypto\n\n[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://protocol.ai)\n[![](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/)\n[![](https://img.shields.io/badge/freenode-%23libp2p-yellow.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23libp2p)\n[![Discourse posts](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg)](https://discuss.libp2p.io)\n[![](https://img.shields.io/codecov/c/github/libp2p/js-libp2p-crypto.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p-crypto)\n[![](https://img.shields.io/travis/libp2p/js-libp2p-crypto.svg?style=flat-square)](https://travis-ci.com/libp2p/js-libp2p-crypto)\n[![Dependency Status](https://david-dm.org/libp2p/js-libp2p-crypto.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-crypto)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)\n\n> Crypto primitives for libp2p in JavaScript\n\nThis repo contains the JavaScript implementation of the crypto primitives needed for libp2p. This is based on this [go implementation](https://github.com/libp2p/go-libp2p-crypto).\n\n## Lead Maintainer\n\n[Friedel Ziegelmayer](https://github.com/dignifiedquire/)\n\n## Table of Contents\n\n- [Install](#install)\n- [API](#api)\n  - [`crypto.hmac`](#cryptohmac)\n    - [`create(hash, secret, callback)`](#cryptohmaccreatehash-secret-callback)\n      - [`digest(data, callback)`](#digestdata-callback)\n  - [`crypto.aes`](#cryptoaes)\n    - [`create(key, iv, callback)`](#cryptoaescreatekey-iv-callback)\n      - [`encrypt(data, callback)`](#encryptdata-callback)\n      - [`decrypt(data, callback)`](#decryptdata-callback)\n  - [`keys`](#cryptokeys)\n    - [`generateKeyPair(type, bits, callback)`](#cryptokeysgeneratekeypairtype-bits-callback)\n    - [`generateEphemeralKeyPair(curve, callback)`](#cryptokeysgenerateephemeralkeypaircurve-callback)\n    - [`keyStretcher(cipherType, hashType, secret, callback)`](#cryptokeyskeystretcherciphertype-hashtype-secret-callback)\n    - [`marshalPublicKey(key[, type], callback)`](#cryptokeysmarshalpublickeykey-type-callback)\n    - [`unmarshalPublicKey(buf)`](#cryptokeysunmarshalpublickeybuf)\n    - [`marshalPrivateKey(key[, type])`](#cryptokeysmarshalprivatekeykey-type)\n    - [`unmarshalPrivateKey(buf, callback)`](#cryptokeysunmarshalprivatekeybuf-callback)\n    - [`import(pem, password, callback)`](#cryptokeysimportpem-password-callback)\n    - [`randomBytes(number)`](#cryptorandombytesnumber)\n    - [`pbkdf2(password, salt, iterations, keySize, hash)`](#cryptopbkdf2password-salt-iterations-keysize-hash)\n- [Contribute](#contribute)\n- [License](#license)\n\n## Install\n\n```sh\nnpm install --save libp2p-crypto\n```\n\n## API\n\n### `crypto.aes`\n\nExpoes an interface to AES encryption (formerly Rijndael), as defined in U.S. Federal Information Processing Standards Publication 197.\n\nThis uses `CTR` mode.\n\n#### `crypto.aes.create(key, iv, callback)`\n\n- `key: Buffer` The key, if length `16` then `AES 128` is used. For length `32`, `AES 256` is used.\n- `iv: Buffer` Must have length `16`.\n- `callback: Function`\n\n##### `decrypt(data, callback)`\n\n- `data: Buffer`\n- `callback: Function`\n\n##### `encrypt(data, callback)`\n\n- `data: Buffer`\n- `callback: Function`\n\n```js\nvar crypto = require('libp2p-crypto')\n\n// Setting up Key and IV\n\n// A 16 bytes array, 128 Bits, AES-128 is chosen\nvar key128 = Buffer.from([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15])\n\n// A 16 bytes array, 128 Bits,\nvar IV = Buffer.from([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15])\n\nasync function main () {\n  let decryptedMessage = 'Hello, world!'\n  let encryptedMessage\n\n  // Encrypting\n  await crypto.aes.create(key128, IV, (err, cipher) => {\n    if (!err) {\n      cipher.encrypt(Buffer.from(decryptedMessage), (err, encryptedBuffer) => {\n        if (!err) {\n          console.log(encryptedBuffer)\n          // prints: <Buffer 42 f1 67 d9 2e 42 d0 32 9e b1 f8 3c>\n          encryptedMessage = encryptedBuffer\n        }\n      })\n    }\n  })\n\n  // Decrypting\n  await crypto.aes.create(key128, IV, (err, cipher) => {\n    if (!err) {\n      cipher.decrypt(encryptedMessage, (err, decryptedBuffer) => {\n        if (!err) {\n          console.log(decryptedBuffer)\n          // prints: <Buffer 42 f1 67 d9 2e 42 d0 32 9e b1 f8 3c>\n\n          console.log(decryptedBuffer.toString('utf-8'))\n          // prints: Hello, world!\n        }\n      })\n    }\n  })\n}\nmain()\n\n```\n\n### `crypto.hmac`\n\nExposes an interface to the Keyed-Hash Message Authentication Code (HMAC) as defined in U.S. Federal Information Processing Standards Publication 198. An HMAC is a cryptographic hash that uses a key to sign a message. The receiver verifies the hash by recomputing it using the same key.\n\n#### `crypto.hmac.create(hash, secret, callback)`\n\n- `hash: String`\n- `secret: Buffer`\n- `callback: Function`\n\n##### `digest(data, callback)`\n\n- `data: Buffer`\n- `callback: Function`\n\nExample:\n\n```js\nvar crypto = require('libp2p-crypto')\n\nlet hash = 'SHA1' // 'SHA256' || 'SHA512'\n\ncrypto.hmac.create(hash, Buffer.from('secret'), (err, hmac) => {\n  if (!err) {\n    hmac.digest(Buffer.from('hello world'), (err, sig) => {\n      if (!err) {\n        console.log(sig)\n      }\n    })\n  }\n})\n```\n\n### `crypto.keys`\n\n**Supported Key Types**\n\nThe [`generateKeyPair`](#cryptokeysgeneratekeypairtype-bits-callback), [`marshalPublicKey`](#cryptokeysmarshalpublickeykey-type-callback), and [`marshalPrivateKey`](#cryptokeysmarshalprivatekeykey-type) functions accept a string `type` argument.\n\nCurrently the `'RSA'` and `'ed25519'` types are supported, although ed25519 keys support only signing and verification of messages.  For encryption / decryption support, RSA keys should be used.\n\nInstalling the [libp2p-crypto-secp256k1](https://github.com/libp2p/js-libp2p-crypto-secp256k1) module adds support for the `'secp256k1'` type, which supports ECDSA signatures using the secp256k1 elliptic curve popularized by Bitcoin.  This module is not installed by default, and should be explicitly depended on if your project requires secp256k1 support.\n\n### `crypto.keys.generateKeyPair(type, bits, callback)`\n\n- `type: String`, see [Supported Key Types](#supported-key-types) above.\n- `bits: Number` Minimum of 1024\n- `callback: Function`\n\nGenerates a keypair of the given type and bitsize.\n\n### `crypto.keys.generateEphemeralKeyPair(curve, callback)`\n\n- `curve: String`, one of `'P-256'`, `'P-384'`, `'P-521'` is currently supported\n- `callback: Function`\n\nGenerates an ephemeral public key and returns a function that will compute the shared secret key.\n\nFocuses only on ECDH now, but can be made more general in the future.\n\nCalls back with an object of the form\n\n```js\n{\n  key: Buffer,\n  genSharedKey: Function\n}\n```\n\n### `crypto.keys.keyStretcher(cipherType, hashType, secret, callback)`\n\n- `cipherType: String`, one of `'AES-128'`, `'AES-256'`, `'Blowfish'`\n- `hashType: String`, one of `'SHA1'`, `SHA256`, `SHA512`\n- `secret: Buffer`\n- `callback: Function`\n\nGenerates a set of keys for each party by stretching the shared key.\n\nCalls back with an object of the form:\n\n```js\n{\n  k1: {\n    iv: Buffer,\n    cipherKey: Buffer,\n    macKey: Buffer\n  },\n  k2: {\n    iv: Buffer,\n    cipherKey: Buffer,\n    macKey: Buffer\n  }\n}\n```\n\n### `crypto.keys.marshalPublicKey(key[, type], callback)`\n\n- `key: keys.rsa.RsaPublicKey | keys.ed25519.Ed25519PublicKey | require('libp2p-crypto-secp256k1').Secp256k1PublicKey`\n- `type: String`, see [Supported Key Types](#supported-key-types) above.\n\nConverts a public key object into a protobuf serialized public key.\n\n### `crypto.keys.unmarshalPublicKey(buf)`\n\n- `buf: Buffer`\n\nConverts a protobuf serialized public key into its  representative object.\n\n### `crypto.keys.marshalPrivateKey(key[, type])`\n\n- `key: keys.rsa.RsaPrivateKey | keys.ed25519.Ed25519PrivateKey | require('libp2p-crypto-secp256k1').Secp256k1PrivateKey`\n- `type: String`, see [Supported Key Types](#supported-key-types) above.\n\nConverts a private key object into a protobuf serialized private key.\n\n### `crypto.keys.unmarshalPrivateKey(buf, callback)`\n\n- `buf: Buffer`\n- `callback: Function`\n\nConverts a protobuf serialized private key into its representative object.\n\n### `crypto.keys.import(pem, password, callback)`\n\n- `pem: string`\n- `password: string`\n- `callback: Function`\n\nConverts a PEM password protected private key into its representative object.\n\n### `crypto.randomBytes(number)`\n\n- `number: Number`\n\nGenerates a Buffer with length `number` populated by random bytes.\n\n### `crypto.pbkdf2(password, salt, iterations, keySize, hash)`\n\n- `password: String`\n- `salt: String`\n- `iterations: Number`\n- `keySize: Number` in bytes\n- `hash: String` the hashing algorithm ('sha1', 'sha2-512', ...)\n\nComputes the Password Based Key Derivation Function 2; returning a new password.\n\n## Contribute\n\nFeel free to join in. All welcome. Open an [issue](https://github.com/libp2p/js-libp2p-crypto/issues)!\n\nThis repository falls under the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).\n\n[![](https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](https://github.com/ipfs/community/blob/master/contributing.md)\n\n## License\n\n[MIT](./LICENSE)\n","readmeFilename":"README.md"}