gpt4 book ai didi

java - 无法让 bouncycaSTLe 在 der 编码中正确标记构造的八位字节字符串

转载 作者:太空宇宙 更新时间:2023-11-04 08:33:35 25 4
gpt4 key购买 nike

我有以下要求。我有一个 asn1 类型,需要封装在构造的八位字节字符串(标记为 0x24 的八位字节字符串)中。然后,该结构在 CMS 签名 block 中进行签名,并且整个 CMS block 需要进行 DER 编码。

我的问题是每次我对 CMS block 进行 DER 编码时,构造的八位字节字符串就会变成(非构造的?)八位字节字符串。我的意思是它的标签从 0x24(我需要的)切换到 0x04。

这是 BouncycaSTLe 的错误还是我做了不应该做的事情?忽略 CMS block ,似乎每当我尝试对“BerConstructedOctetString”进行编码时,它就不再是构造的八位字节字符串:

BERConstructedOctetString constructed = new BERConstructedOctetString(new DERInteger(3));
ASN1Object nonConstructed= new DEROctetString(new DERInteger(3));

System.out.println(Util.toHex(constructed.getDEREncoded()));
System.out.println(Util.toHex(nonConstructed.getDEREncoded()));
System.out.println(Util.toHex(constructed.getEncoded()));
System.out.println(Util.toHex(nonConstructed.getEncoded()));

输出如下:

04:03:02:01:03
04:03:02:01:03
24:80:04:03:02:01:03:00:00
04:03:02:01:03

编辑:这可能吗? bouncycaSTLe 和 not-yet-commons-ssl 是否都包含“BerConstructedOctetString”,在编码为 DER 时将其编码和标记为 0x04?我的两个要求不兼容吗?

最佳答案

我总是去this reference来自旧 RSA 实验室,回答有关 BER/DER 编码的问题。在这种情况下,请查看第 4 节中的规则#3(DER 编码规则):

3. For simple string types and implicitly tagged types derived from
simple string types, the primitive, definite-length method must be
employed.

如果我没看错的话,如果您要求 DER 编码,这会强制使用 0x04 进行原始编码。

关于java - 无法让 bouncycaSTLe 在 der 编码中正确标记构造的八位字节字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6931212/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com