简体   繁体   English

如何将 ASN.1 的大 integer(公钥)INTEGER 放入结构的小 int64 中?

[英]How can I fit large integer (public key) INTEGER of ASN.1 into small int64 of struct?

I have to represent (ASN.1/DER SEQUENCE) pseudocode :我必须表示 (ASN.1/DER SEQUENCE)伪代码

SEQUENCE ::= {
      INTEGER
      SEQUENCE {...}
      ...
}

Where INTEGER should be a PUBLIC KEY其中INTEGER应该是公钥

In terms of Golang struct I have so far pseudocode :就 Golang 结构而言,我到目前为止有伪代码

type ... struct {
      num int64,
      ...
}

But when compile, I got runtime error, saying:但是在编译时,出现运行时错误,说:

panic: asn1: structure error: integer too large

I understand, that problem is with fitting LARGE PUBLIC KEY into small int64, how should I overcome that problem?我知道,这个问题是将 LARGE PUBLIC KEY 放入 small int64 中,我应该如何克服这个问题? When I change num int64 to num []int64 I got another error, saying, that type mismatch (which also MAKE SENSE, since was INTEGER and now SEQUENCE)...当我将num int64更改为num []int64时,我得到了另一个错误,说类型不匹配(这也是有道理的,因为是 INTEGER,现在是 SEQUENCE)...

So, again, how do you fit PUBLIC KEY INTEGER into int of Golang or any other prog.所以,再一次,你如何将 PUBLIC KEY INTEGER 放入 Golang 或任何其他程序的 int 中。 lang?郎?

I think this could help you: Why is unmarshalling of a DER ASN.1 large integer limited to SEQUENCE in Golang?我认为这可以帮助您: Why is unmarshalling of a DER ASN.1 large integer limited to SEQUENCE in Golang? (look at the answer) (看答案)

Note on your comment: Go Big.Int is NOT an asn1 SEQUENCE (asn1 is agnostic, it is up to you or the tool you use to define how you will map asn1 INTEGER to something you can use)请注意您的评论:Go Big.Int is NOT an asn1 SEQUENCE(asn1 是不可知的,这取决于您或您使用的工具来定义您将如何将 map asn1 INTEGER 用于您可以使用的东西)

ASN.1 does not put a limit on the size of an INTEGER, which is one reason INTEGER is used to represent the large public key. ASN.1 没有限制 INTEGER 的大小,这是 INTEGER 用于表示大公钥的原因之一。 Several programming languages have a "Big.INT" representation that can be used to handle such large integers.多种编程语言都有“Big.INT”表示法,可用于处理如此大的整数。 Some commercial ASN.1 Tools have an alternate representation for handling such large integers in target languages such as C or C++ which don't have a Big INT representation.一些商业 ASN.1 工具有一个替代表示,用于处理目标语言中的此类大整数,例如 C 或 C++,它们没有大 INT 表示。 In your case, int64 is not sufficient to handle public key integer which can be more than 128 bits in length.在您的情况下,int64 不足以处理长度超过 128 位的公钥 integer。 You will need to determine how your ASN.1 tool handles huge integers, or you may consider using an ASN.1 tool that does support big integers.您将需要确定您的 ASN.1 工具如何处理大整数,或者您可以考虑使用支持大整数的 ASN.1 工具。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM