add global bin for generating keypairs

This commit is contained in:
AJ ONeal 2016-08-17 00:22:07 -06:00
parent 982c13948a
commit f3d8bb85c1
3 changed files with 64 additions and 1 deletions

View File

@ -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) (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 Examples
-------- --------

35
bin/rsa-keygen.js Executable file
View File

@ -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);
});

View File

@ -3,6 +3,9 @@
"version": "1.2.6", "version": "1.2.6",
"description": "RSA utils that work on Windows, Mac, and Linux with or without C compiler", "description": "RSA utils that work on Windows, Mac, and Linux with or without C compiler",
"main": "node.js", "main": "node.js",
"bin": {
"rsa-keygen-js": "bin/rsa-keygen.js"
},
"scripts": { "scripts": {
"test": "node tests" "test": "node tests"
}, },
@ -36,7 +39,7 @@
}, },
"homepage": "https://github.com/Daplie/rsa-compat.js#readme", "homepage": "https://github.com/Daplie/rsa-compat.js#readme",
"dependencies": { "dependencies": {
"buffer-v6-polyfill": "^1.0.1", "buffer-v6-polyfill": "^1.0.3",
"node-forge": "^0.6.41" "node-forge": "^0.6.41"
}, },
"optionalDependencies": { "optionalDependencies": {