简体   繁体   中英

cms Enveloped Data binary encoding problem in pkijs

I'm trying trying to implement exchange of CMS encrypted content using the pkijs library. Basically I've just copied the example from here: https://pkijs.org/examples/CMSEnvelopedExample.html

here the excerpt for encryption

cmsEnveloped.addRecipientByCertificate(certSimpl, {  oaepHashAlgorithm: oaepHashAlg });

return cmsEnveloped.encrypt(encAlg, valueBuffer).then(() => {
  var cmsContentSimpl = new ContentInfo();
  cmsContentSimpl.contentType = "1.2.840.113549.1.7.3";
  cmsContentSimpl.content = cmsEnveloped.toSchema();
  cmsEnvelopedBuffer = cmsContentSimpl.toSchema().toBER(false);

The problematic part is the binary encoding of the asn.1 schema with .toBER(false) . If the valueBuffer is not extremely small it is very slow ~13sek for 1 Mb. My question are: why is this so slow? and could I just encode it differently eg toJSON() and then stringToArrayBuffer ? Are there any security concerns?

There was some unoptimized code in the implementation of toBER in asn1js . You should upgrade the dependency to asn1js@2.4.0 if you encounter the same problem. This is the issue on github: https://github.com/PeculiarVentures/PKI.js/issues/347

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM