24 lines
567 B
JavaScript
24 lines
567 B
JavaScript
'use strict';
|
|
|
|
var pubkey = require('./pubkey.js');
|
|
var pubname = process.argv[2];
|
|
var fs = require('fs');
|
|
var pem = fs.readFileSync(pubname);
|
|
|
|
var key = pubkey.parsePem(pem);
|
|
if ('RSA' !== key.typ) {
|
|
throw new Error(key.typ + " not supported");
|
|
}
|
|
if (key.pub) {
|
|
var pubbuf = pubkey.readPubkey(key.der);
|
|
} else {
|
|
var pubbuf = pubkey.readPrivkey(key.der);
|
|
}
|
|
|
|
console.log(pubbuf.byteLength, pubkey.toHex(pubbuf));
|
|
var der = pubkey.toRsaPub(pubbuf);
|
|
var b64 = pubkey.toBase64(der);
|
|
var pem = pubkey.formatAsPublicPem(b64);
|
|
console.log('Pub:\n');
|
|
console.log(pem);
|