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

标签 java bouncycastle asn.1

我有以下要求。我有一个 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/

相关文章:

java - Firestore 查询 - 检查用户名是否已存在

c# - 无法通过 SslStream 发送客户端证书

java - BouncyCaSTLe 签名字符串中的奇怪字符

xml - 使用 DSIG 为 XML 添加时间戳

cryptography - bouncycaSTLe 中的 PKCS #7 SignedData 问题

java - 用于验证字母数字或一组特殊字符的正则表达式

java - 如何从多个线程更新缓存

java - 在此示例中,lambdas 和引用方法如何工作?

java - 充气城堡 : remove algorithm protection attribute from signerInfos

python - 解码 Scapy ASN1 编码的 SSL/TLS 证书字段