[英]How to get the size of DER structure?
I need to learn the length of Der structure.我需要学习 Der 结构的长度。 It's used as a header for the cipher text file.它用作密文文件的 header。 My cipher writes the DER encoded data and the ciphertext back to back to the (cipher text) file.我的密码将 DER 编码数据和密文写回(密文)文件。
I need to learn the size of the DER structure so I can pass it and only get the ciphertext from the cipher text file for decoding it.我需要了解 DER 结构的大小,以便我可以传递它并且只从密文文件中获取密文以对其进行解码。 I know, I need to parse the length byte (or bytes) of header's outer asn1 sequence to get that info, but I don't know how to do it since I am not sure how many bytes it takes to store that length data.我知道,我需要解析标头的外部 asn1 序列的长度字节(或字节)以获取该信息,但我不知道该怎么做,因为我不确定存储该长度数据需要多少字节。
I put the DER Header down below to give a basic idea.我把 DER Header 放在下面给出一个基本的想法。 I would appreciate if you can take a look on it.如果您能看一看,我将不胜感激。
Header = \
asn1_sequence(
asn1_sequence(
asn1_octetstring(salt)+
asn1_integer(iter)+
asn1_integer(len(key))
) +
asn1_sequence(
asn1_objectidentifier([2,16,840,1,101,3,4,1,2])+
asn1_octetstring(iv_current)
)+
asn1_sequence(
asn1_sequence(
asn1_objectidentifier([2,16,840,1,101,3,4,2,1])+
asn1_null()
)+
asn1_octetstring(digestinfo)
)
)
Your data is encoded with DER, this means it uses TLV (Tag Length Value) form.您的数据使用 DER 编码,这意味着它使用 TLV(标签长度值)形式。
To know the length of the Value, you will have to read the Tag and the Length.要知道值的长度,您必须阅读标签和长度。
Reading Tag and Length is not trivial and it is explained in Recommendation X.690读取标签和长度并不简单,在X.690 推荐中有解释
Depending on which language you want to use, you should be able to find some code to use or hack.根据您要使用的语言,您应该能够找到一些代码来使用或破解。
This lib would be used like this这个库会像这样使用
BERReader reader = new BERReader(input);
reader.readTag();
reader.readLength();
reader.getLengthValue(); // gives you how many bytes you have to read
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.