CMS包裹的数据二进制编码问题在PKIJS中

发布于 2025-01-23 12:39:59 字数 868 浏览 3 评论 0原文

我正在尝试使用PKIJS库来实施CMS加密内容的交换。 基本上,我刚刚从这里复制了示例: https://pkijs.org/pkijs.orgs.org/exmples/cmsenvelodevelvevedexample.htmamplecampledexample.htmll

在这里加密的摘录

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

是有问题的部分是用.tober(false)对ASN的二进制编码。 如果ValueBuffer不太小,则非常慢,〜13Sek对于1 MB。 我的问题是:为什么这么慢?我可以用不同的方式对其进行编码,例如tojson(),然后stringtoArrayBuffer?有任何安全问题吗?

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 e.g. toJSON()and then stringToArrayBuffer? Are there any security concerns?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

初与友歌 2025-01-30 12:39:59

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文