CMS包裹的数据二进制编码问题在PKIJS中
我正在尝试使用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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在
tober
中,asn1js
的实现中有一些不优化的代码。您应该将依赖项升级到>如果您遇到相同的问题。这是github上的问题: https://github.com/peculiarventures/peculiarventures/peculiarventures/pki.js /esseage/347
There was some unoptimized code in the implementation of
toBER
inasn1js
. 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