简体   繁体   English

如何获得DER结构的大小?

[英]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 推荐中有解释

  • 8.1.2 Identifier octets 8.1.2 标识符八位字节
  • 8.1.3 Length octets 8.1.3 长度八位字节

Depending on which language you want to use, you should be able to find some code to use or hack.根据您要使用的语言,您应该能够找到一些代码来使用或破解。

Example in Java Java中的示例

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.

相关问题 如何将 .der 文件转换为 .pub? - How to convert the .der file to .pub? 客观C密码术:如何获得各种长度的相等大小的加密数据 - objective c cryptography: how to get equal size of encrypted data for various length 如何使用精确的大小计算存储AES_encrypt大小密码? - How to store AES_encrypt size cipher with exact size calculation? 如何解密不是块大小倍数的数据? - How can I decrypt the data which size is not multiple of block size? java.security.spec.InvalidKeySpecException:java.security.InvalidKeyException:IOException:DER 输入,整数标记错误 - java.security.spec.InvalidKeySpecException: java.security.InvalidKeyException: IOException : DER input, Integer tag error 创建密码实例 Objective-C 并获取块大小 - Create Cipher Instance Objective-C and get Block Size AES:如何为每种算法大小从密码生成密钥 - AES: how to generate Key from password for every algorithm size 如何在swift 3的ios中使用commoncrypto加密大文件? - How to encrypt large size files with commoncrypto in ios in swift 3? 如何使用密钥大小为 128 的 CryptoJS 在 AES 中加密? - How to encrypt in AES using CryptoJS with key size of 128? 如何修复 Javascript 中的“密文大小无效”错误? (aes) - How to fix 'invalid ciphertext size' error in Javascript ? (aes)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM