Browse Source

add global bin for generating keypairs

pull/1/head
AJ ONeal 8 years ago
parent
commit
f3d8bb85c1
  1. 25
      README.md
  2. 35
      bin/rsa-keygen.js
  3. 5
      package.json

25
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
--------

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

5
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": {

Loading…
Cancel
Save