How to use the pkcs7 function from node-forge

Find comprehensive JavaScript node-forge.pkcs7 code examples handpicked from public code repositorys.

215
216
217
218
219
220
221
222
223
224
}

public encrypt(value: string, publicKey: string): any
{
    const cert = forge.pki.certificateFromPem(publicKey);
    const p7 = forge.pkcs7.createEnvelopedData();
    p7.addRecipient(cert);
    p7.content = forge.util.createBuffer();
    p7.content.putString(value);
    p7.encrypt();
fork icon0
star icon56
watch icon7

154
155
156
157
158
159
160
161
162
163
  pem.clientprivate = forge.pki.privateKeyToPem(clientkeys.privateKey);
  pem.clientpublic = forge.pki.publicKeyToPem(clientkeys.publicKey);
  pem.clientcert = forge.pki.certificateToPem(clientcert);

  if (options.pkcs7) {
    var clientp7 = forge.pkcs7.createSignedData();
    clientp7.addCertificate(clientcert);
    pem.clientpkcs7 = forge.pkcs7.messageToPem(clientp7);
  }
}
fork icon0
star icon1
watch icon1

+ 7 other calls in file

202
203
204
205
206
207
208
209
210
211
})[forge.pki.oids.pkcs8ShroudedKeyBag];

// pega chave privada do certificado
const privateKey = keyBags[0].key;
// Cria pkcs7.
const p7 = forge.pkcs7.createSignedData();
// coloca o conteúdo como sendo os bytes do pdf.
p7.content = forge.util.createBuffer(pdf.toString('binary'));

// Adiciona certificados e chaves públicas ao pkcs7
fork icon0
star icon0
watch icon1

+ 14 other calls in file

68
69
70
71
72
73
74
75
76
77
            "Access-Control-Allow-Origin": "*"
        },
    }
)
// Lê PKCS7
const pkcs7 = forge.pkcs7.messageFromPem(res.data)
// exporta a chave privada gerada no começo para pkcs8 e bota ela num arquivo
const exported = await window.crypto.subtle.exportKey("pkcs8", keys.privateKey)
const exportedAsString = ab2str(exported);
const exportedAsBase64 = window.btoa(exportedAsString);
fork icon0
star icon0
watch icon1

+ 81 other calls in file