font-weight: bold;}.hljs-deletion{background: #fdd;}.hljs-addition{background: #dfd;}.hljs-emphasis{font-style: italic;}.hljs-strong{font-weight: bold;}</style><divstyle="margin-bottom:104px;"data-radium="true"><h1data-radium="true"><aclass="anchor"name="intro"></a>Intro</h1><div><p>Installable via <code>npm install --save libp2p-crypto</code>, it can also be used directly in the browser.</p>
<h2>Download</h2>
<p>The source is available for download from <ahref="https://github.com/libp2p/js-libp2p-crypto.git">GitHub</a>. Alternatively, you can install using npm:</p>
<p>The portable versions of libp2p-crypto, including <code>index.js</code> and <code>index.min.js</code>, are included in the <code>/dist</code> folder. Libp2p-crypto can also be found on <ahref="https://unpkg.com">unpkg.com</a> under</p>
<p>The key id is the base58 encoding of the SHA-256 multihash of its public key.
The public key is a protobuf encoding containing a type and the DER encoding
of the PKCS SubjectPublicKeyInfo.</p>
</div><divdata-radium="true"><h4>Parameters</h4><olstyle="list-style:none;margin-left:0;padding-left:0;"data-radium="true"><divdata-radium="true"><listyle="padding-bottom:13px;"data-radium="true"><code>callback: function (<ahref="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error">Error</a>, id)</code>: <divstyle="display:inline-block;"data-radium="true"></div></li></div></ol></div><divdata-radium="true"><h4>Returns</h4><divdata-radium="true"><code><ahref="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/undefined">undefined</a></code><span>
</span></div></div></div><divstyle="margin-bottom:104px;"data-radium="true"><h1data-radium="true"><aclass="anchor"name="export"></a>export<ahref="https://git@github.com/:libp2p/js-libp2p-crypto/blob/857d2bd9024bcfb0365d0b41967d8fb02b9dae38/src/keys/rsa-class.js#L123-L157"title="src/keys/rsa-class.js"style="float:right;"data-radium="true"><svgfill="currentColor"preserveAspectRatio="xMidYMid meet"height="1em"width="1em"viewBox="0 0 40 40"style="vertical-align:middle;"><g><pathd="m26.3 7.5l-3.8 3.8 8.8 8.7-8.8 8.8 3.8 3.7 11.2-12.5-11.2-12.5z m-12.5 0l-11.3 12.5 11.3 12.5 3.7-3.7-8.7-8.8 8.7-8.7-3.7-3.8z"></path></g></svg></a></h1><div><p>Exports the key into a password protected PEM format</p>
</div><divdata-radium="true"><h4>Parameters</h4><olstyle="list-style:none;margin-left:0;padding-left:0;"data-radium="true"><divdata-radium="true"><listyle="padding-bottom:13px;"data-radium="true"><code>format: <ahref="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>?</code>: <divstyle="display:inline-block;"data-radium="true">Defaults to 'pkcs-8'.
</div></li></div><divdata-radium="true"><listyle="padding-bottom:13px;"data-radium="true"><code>password: <ahref="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String">string</a></code>: <divstyle="display:inline-block;"data-radium="true">The password to read the encrypted PEM
</div></li></div><divdata-radium="true"><listyle="padding-bottom:13px;"data-radium="true"><code>callback: function (<ahref="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error">Error</a>, KeyInfo)</code>: <divstyle="display:inline-block;"data-radium="true"></div></li></div></ol></div><divdata-radium="true"><h4>Returns</h4><divdata-radium="true"><code><ahref="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/undefined">undefined</a></code><span>
</span></div></div></div><divstyle="margin-bottom:104px;"data-radium="true"><h1data-radium="true"><aclass="anchor"name="id"></a>id<ahref="https://git@github.com/:libp2p/js-libp2p-crypto/blob/857d2bd9024bcfb0365d0b41967d8fb02b9dae38/src/keys/ed25519-class.js#L92-L99"title="src/keys/ed25519-class.js"style="float:right;"data-radium="true"><svgfill="currentColor"preserveAspectRatio="xMidYMid meet"height="1em"width="1em"viewBox="0 0 40 40"style="vertical-align:middle;"><g><pathd="m26.3 7.5l-3.8 3.8 8.8 8.7-8.8 8.8 3.8 3.7 11.2-12.5-11.2-12.5z m-12.5 0l-11.3 12.5 11.3 12.5 3.7-3.7-8.7-8.8 8.7-8.7-3.7-3.8z"></path></g></svg></a></h1><div><p>Gets the ID of the key.</p>
<p>The key id is the base58 encoding of the SHA-256 multihash of its public key.
The public key is a protobuf encoding containing a type and the DER encoding
of the PKCS SubjectPublicKeyInfo.</p>
</div><divdata-radium="true"><h4>Parameters</h4><olstyle="list-style:none;margin-left:0;padding-left:0;"data-radium="true"><divdata-radium="true"><listyle="padding-bottom:13px;"data-radium="true"><code>callback: function (<ahref="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error">Error</a>, id)</code>: <divstyle="display:inline-block;"data-radium="true"></div></li></div></ol></div><divdata-radium="true"><h4>Returns</h4><divdata-radium="true"><code><ahref="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/undefined">undefined</a></code><span>
</div></li></div><divdata-radium="true"><listyle="padding-bottom:13px;"data-radium="true"><code>hash: <ahref="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String">string</a></code>: <divstyle="display:inline-block;"data-radium="true">The hash name ('sha1', 'sha2-512, ...)
</div></li></div></ol></div><divdata-radium="true"><h4>Returns</h4><divdata-radium="true"><code><ahref="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String">string</a></code><span> A new password