rasha-fork/bin/rasha.js

34 lines
742 B
JavaScript
Raw Normal View History

2018-11-21 23:47:41 +00:00
#!/usr/bin/env node
'use strict';
2018-11-22 01:44:46 +00:00
2018-11-22 07:39:43 +00:00
var fs = require('fs');
var Rasha = require('../index.js');
2018-11-22 00:25:05 +00:00
2018-11-22 07:39:43 +00:00
var infile = process.argv[2];
var format = process.argv[3];
2018-11-21 23:47:41 +00:00
2018-11-22 07:39:43 +00:00
var key = fs.readFileSync(infile, 'ascii');
2018-11-21 23:47:41 +00:00
2018-11-22 07:39:43 +00:00
try {
key = JSON.parse(key);
} catch(e) {
// ignore
2018-11-21 23:47:41 +00:00
}
2018-11-22 07:39:43 +00:00
if ('string' === typeof key) {
var pub = (-1 !== [ 'public', 'spki', 'pkix' ].indexOf(format));
Rasha.import({ pem: key, public: (pub || format) }).then(function (jwk) {
2018-11-22 09:36:21 +00:00
console.info(JSON.stringify(jwk, null, 2));
2018-11-22 07:39:43 +00:00
}).catch(function (err) {
console.error(err);
process.exit(1);
});
} else {
Rasha.export({ jwk: key, format: format }).then(function (pem) {
2018-11-22 09:36:21 +00:00
console.info(pem);
2018-11-22 07:39:43 +00:00
}).catch(function (err) {
console.error(err);
process.exit(2);
2018-11-22 01:49:57 +00:00
});
}