node-gapitoken icon indicating copy to clipboard operation
node-gapitoken copied to clipboard

Support p12 file format natively

Open erlichmen opened this issue 10 years ago • 3 comments

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.

erlichmen avatar Oct 14 '13 19:10 erlichmen

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

bsphere avatar Oct 14 '13 22:10 bsphere

+1 not sure why this was closed.

objectiveSee avatar Oct 14 '14 18:10 objectiveSee

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

Mr0grog avatar Feb 12 '15 01:02 Mr0grog