ECC公钥eccpubkey的ASN.1编码规则

来源:互联网 发布:大数据合作协议 编辑:程序博客网 时间:2024/06/05 06:41

自己在工作中,需要用到ECC公钥的asn.1编码,ECC公钥的asn.1格式是bit string。

这次碰到了一个bit string的开头是这样的,03 4200 04c5 d21e ......

03是bit string的tag,42是bit string的length,00是bit string的unused bit。

我们知道ecc的公钥是64个字节长,也就是0x40,那么问题出来了,下面那个字节,04是什么呢?

在网上查询资料,没找到,因为pkcs13只是ecc的draft,而且是很简单的说了下,没有涉及到ecc的asn.1格式,

后来几经波折,终于找到了ECC的标准draft,网址是,ECC—draft。

看了这个文档后的摘录如下,

ECC的公钥格式是,

SubjectPublicKeyInfo  ::=  SEQUENCE  {
       algorithm         AlgorithmIdentifier,
       subjectPublicKey  BIT STRING
 }

 The subjectPublicKey from SubjectPublicKeyInfo is the ECC public key.
 ECC public keys have the following syntax:
    ECPoint ::= OCTET STRING

这里的OCTET STRING的开头就是从04开始的,

The first octet of the OCTET STRING indicates whether the key
is compressed or uncompressed.  The uncompressed form is
indicated by 0x04 and the compressed form is indicated by
either 0x02 or 0x03。

这下就知道了,04说明是没有压缩的。剩下的0x40个字节就是ECC的公钥point了。

原创粉丝点击