How to use the pkcs12 function from node-forge
Find comprehensive JavaScript node-forge.pkcs12 code examples handpicked from public code repositorys.
GitHub: elecV2/elecV2P
116 117 118 119 120 121 122 123 124 125
const key = fs.readFileSync(keyPath) const crt = fs.readFileSync(crtPath) const prikey = forge.pki.privateKeyFromPem(key.toString()) const pubcrt = forge.pki.certificateFromPem(crt.toString()) const p12Asn1 = forge.pkcs12.toPkcs12Asn1(prikey, pubcrt, password) const p12Der = forge.asn1.toDer(p12Asn1).getBytes() const p12b64 = forge.util.encode64(p12Der) return p12b64
333
0
36
+ 3 other calls in file
257 258 259 260 261 262 263 264 265 266
// we're only handling the common case of file import/export password (integrity) // being the same as encrypted private key passphrase (privacy) // see -twopass arg for openssl: https://linux.die.net/man/1/pkcs12 let pkcs12Obj = {}; if (typeof options.importPassword === 'undefined') { pkcs12Obj = forge.pkcs12.pkcs12FromAsn1(pkcs12Asn1); } else { pkcs12Obj = forge.pkcs12.pkcs12FromAsn1(pkcs12Asn1, options.importPassword); } return {
56
139
51
174 175 176 177 178 179 180 181 182 183
fs.outputFileSync(userKeyPath, privateKeyPem); let p12Asn1; //create .p12 file if (rootCaCert) { p12Asn1 = forge.pkcs12.toPkcs12Asn1( keys.privateKey, [cert, caCert, rootCaCert], password, {
30
76
11
+ 3 other calls in file
65 66 67 68 69 70 71 72 73 74
function checkP12Password(file, password) { try { let p12Der = fs.readFileSync(file).toString('binary'); let p12Asn1 = forge.asn1.fromDer(p12Der); forge.pkcs12.pkcs12FromAsn1(p12Asn1, password); } catch(err) { console.log(err.message); return false; }
16
49
11
+ 3 other calls in file
58 59 60 61 62 63 64 65 66 67
const p12Der = _nodeForge.util.decode64(p12base64); const p12Asn1 = _nodeForge.asn1.fromDer(p12Der); const p12 = _nodeForge.pkcs12.pkcs12FromAsn1(p12Asn1, password); const keyObj = getKey(p12); const { ca,
3
0
0
89 90 91 92 93 94 95 96 97 98
// Getting the certificate var filePath = path.resolve('Resource/testrest.p12'); var p12Buffer = fs.readFileSync(filePath); var p12Der = forge.util.binary.raw.encode(new Uint8Array(p12Buffer)); var p12Asn1 = forge.asn1.fromDer(p12Der); var certificate = forge.pkcs12.pkcs12FromAsn1(p12Asn1, false, keyPass); // Getting the RSA private key // get rsa key bags
0
0
1
+ 64 other calls in file
GitHub: cavrau/assinador-tcc
77 78 79 80 81 82 83 84 85 86
const exportedAsBase64 = window.btoa(exportedAsString); const pemExported = `-----BEGIN PRIVATE KEY-----\n${exportedAsBase64}\n-----END PRIVATE KEY-----`; // lê chave privada de um arquivo const privateKey = forge.pki.privateKeyFromPem(pemExported); // Cria um pkcs12 com a chave privada e os certificados do pkcs7 recebido const p12Asn1 = forge.pkcs12.toPkcs12Asn1(privateKey, pkcs7.certificates, ''); // Lê pkcs12 var pkcs12 = forge.pkcs12.pkcs12FromAsn1(p12Asn1, false, ""); // Assina o PDF
0
0
1
+ 163 other calls in file
node-forge.pki is the most popular function in node-forge (10287 examples)