Permalink
Browse files

rsa generator 5000

  • Loading branch information...
0 parents commit d903ef476bbfa8846149bae4cacfbb91368c68d4 @substack committed Nov 2, 2012
Showing with 71 additions and 0 deletions.
  1. +10 −0 cmd.js
  2. +39 −0 index.js
  3. +22 −0 readme.markdown
10 cmd.js
@@ -0,0 +1,10 @@
+#!/usr/bin/env node
+var rsa = require('./');
+rsa(function (err, doc) {
+ if (err) {
+ console.error(err);
+ process.exit(1);
+ return;
+ }
+ console.log(JSON.stringify(doc, null, 2));
+});
@@ -0,0 +1,39 @@
+var spawn = require('child_process').spawn;
+var fs = require('fs');
+
+module.exports = function (cb) {
+ var n = Math.floor(Math.pow(16, 8) * Math.random());
+ var tmpFile = '/tmp/' + n.toString(16);
+ var bits = 1000 + Math.floor(Math.random() * 100);
+
+ var args = [ '-f', tmpFile, '-b', bits, '-N', '', '-q' ];
+ var ps = spawn('ssh-keygen', args);
+
+ ps.on('exit', function (code) {
+ if (code !== 0) return cb('non-zero code ' + code);
+ var args = [ '-e', '-f', tmpFile + '.pub', '-m', 'PEM' ];
+ var ps = spawn('ssh-keygen', args);
+ var pem = '';
+ ps.stdout.on('data', function (buf) { pem += buf });
+ ps.stdout.on('end', function () {
+ fs.readFile(tmpFile, 'utf8', function (err, priv) {
+ fs.unlink(tmpFile);
+ fs.unlink(tmpFile + '.pub');
+
+ if (err) return cb(err);
+
+ cb(null, {
+ private : priv,
+ public : pem
+ });
+ });
+ });
+
+ ps.on('exit', function (code) {
+ if (code !== 0) {
+ cb('non-zero exit code ' + code);
+ cb = function () {};
+ }
+ });
+ });
+};
@@ -0,0 +1,22 @@
+# rsa-json
+
+generate rsa keypairs as json blobs
+
+# example
+
+```
+$ rsa-json
+{
+ "private": "-----BEGIN RSA PRIVATE KEY-----\nMIICagIBAAKBhADANhcuzGaa+qW/bCqEiPw5GzC+EKHFUgUonEejR2MkT938cmYP\ntKOYtvwhP4GfvnOMds63+Rx0SqGNa87z2V0RvYU7DFtB8cmqxgqIlpzv+J5qh+32\n7UpIwUSQYyOld+XKQcRHQFq7dwsb4bDcGErhbrD7olZzoAVkEK1CO0nIY9JlGQID\nAQABAoGEALws+HtPj3BQzS5f1ixU9CFwVkLtg4LrrrM4dQYMYKpvKpP456Seo79h\n/esLAnuC+BrfQbhpQQs0+X67uiuPdQdmGa8iPUhtpDSX5II3+9vjbJmpoehD5lAi\n0BD9pbgkpmPc9YnE6hUFoKWNU5CnFVh/5Eefn9Y1VZErEMIXaAjf0E7RAkIO5Dgx\n4n1X0q9XDp+WR+sO5YFZNE5H13KSDLjT5QFy20FPoCx20AY0yvweitNFBIi+1b8T\ne9DhZf8q55UKdf++860CQgzoT6Mn5RpOr5mb6uVttepHam+EsZWh1z++ayrjrj0N\nFKnJvqMqtfTk9Nc2VK76p4gi+bcbxylcZosnw8bMxpFEnQJCCrjRqUFNRHWi38jc\nqOTBXylqN6NMlbePe48DaTXjFCK/5KgMO8POJCbe3tLQCUqZduYJvOqSXCgHUIoL\nqsuJR6DFAkIDnwEIkt6xXLXi8F0b9IV+rn5rvtxbUEYk+fTy2WE+e3b6k0DKYece\nR0VxQyrK1EM/7CAGgOKE9glGrOc91KE4i/kCQgkmK6aMv60S5JqeAanzn9eNbdmA\nQrh75sHVwK8rSW/IbgE/uKpK0RCkYD5Fd+L+FUqsDWlrof2CJFxZwBzKNbRliw==\n-----END RSA PRIVATE KEY-----\n",
+ "public": "-----BEGIN RSA PUBLIC KEY-----\nMIGMAoGEAMA2Fy7MZpr6pb9sKoSI/DkbML4QocVSBSicR6NHYyRP3fxyZg+0o5i2\n/CE/gZ++c4x2zrf5HHRKoY1rzvPZXRG9hTsMW0HxyarGCoiWnO/4nmqH7fbtSkjB\nRJBjI6V35cpBxEdAWrt3CxvhsNwYSuFusPuiVnOgBWQQrUI7Schj0mUZAgMBAAE=\n-----END RSA PUBLIC KEY-----\n"
+}
+```
+
+# usage
+
+```
+usage: rsa-json
+
+ Generate a json blob with a new public and private key PEM in it.
+
+```

0 comments on commit d903ef4

Please sign in to comment.