node-gapitoken
node-gapitoken copied to clipboard
Support p12 file format natively
Since Google provides the private key natively in p12 format I think it will be best to support that format out of the box (including password) without the need to convert the file into PEM format.
If you can extract the key from the PKCS#12 file, simply pass it as the key parameter to https://github.com/bsphere/node-gapitoken.
I tried unsuccessfully to extract the key with both https://github.com/digitalbazaar/forge and http://nodejs.org/api/crypto.html#crypto_crypto_createcredentials_details
+1 not sure why this was closed.
This worked for me with node-forge:
var forge = require("node-forge");
var p12Buffer = fs.readFileSync("thekey.p12");
var p12Base64 = p12Buffer.toString("base64");
var p12Der = forge.util.decode64(p12Base64);
var p12Asn1 = forge.asn1.fromDer(p12Der);
var p12 = forge.pkcs12.pkcs12FromAsn1(p12Asn1, 'notasecret');
var keyData = p12.getBags({friendlyName: 'privatekey'}).friendlyName[0].key;
var key = forge.pki.privateKeyToPem(keyData);