diff --git a/README.md b/README.md index 0eaa983..69af04e 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,31 @@ This is useful for **certbot** and **letsencrypt**. (in the future we'd like to provide the same API to the browser) +Install +======= + +``` +# node.js +npm install --save rsa-compat + +# CLI +npm install --global rsa-compat +``` + + +Usage +===== + +CLI +--- + +You can generate keypairs on Windows, Mac, and Linux using rsa-keygen-js: + +```bash +# generates a new keypair in the current directory +rsa-keypiar-js +``` + Examples -------- diff --git a/bin/rsa-keygen.js b/bin/rsa-keygen.js new file mode 100755 index 0000000..e65176f --- /dev/null +++ b/bin/rsa-keygen.js @@ -0,0 +1,35 @@ +#!/usr/bin/env node +'use strict'; + +var RSA = require('../').RSA; +var path = require('path'); +var fs = require('fs'); + +var bitlen = 2048; +var exp = 65537; +var opts = { public: true, pem: true }; +var cwd = process.cwd(); +var privkeyPath = path.join(cwd, 'privkey.pem'); +var pubkeyPath = path.join(cwd, 'pubkey.pem'); + +if (fs.existsSync(privkeyPath)) { + console.error(privkeyPath, "already exists"); + process.exit(1); +} + +RSA.generateKeypair(bitlen, exp, opts, function (err, keypair) { + console.info(''); + console.info(''); + + fs.writeFileSync(privkeyPath, keypair.privateKeyPem, 'ascii'); + console.info(privkeyPath + ':'); + console.info(''); + console.info(keypair.privateKeyPem); + + console.info(''); + + fs.writeFileSync(pubkeyPath, keypair.publicKeyPem, 'ascii'); + console.info(pubkeyPath + ':'); + console.info(''); + console.info(keypair.publicKeyPem); +}); diff --git a/package.json b/package.json index 7e507ac..7261ab1 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,9 @@ "version": "1.2.6", "description": "RSA utils that work on Windows, Mac, and Linux with or without C compiler", "main": "node.js", + "bin": { + "rsa-keygen-js": "bin/rsa-keygen.js" + }, "scripts": { "test": "node tests" }, @@ -36,7 +39,7 @@ }, "homepage": "https://github.com/Daplie/rsa-compat.js#readme", "dependencies": { - "buffer-v6-polyfill": "^1.0.1", + "buffer-v6-polyfill": "^1.0.3", "node-forge": "^0.6.41" }, "optionalDependencies": {