[轉] DER編碼和ASN.1

來源:互聯網
上載者:User

標籤:repr   fas   struct   director   explicit   ogr   pre   alter   serial   

轉載地址:http://blog.csdn.net/taolinke/article/details/6220403

 

DER(Distinguished Encoding Rules,可辨別編碼規則)。

ASN.1抽象文法標記(Abstract Syntax Notation One) ASN.1是一種 ISO/ITU-T 標準,描述了一種對資料進行表示、編碼、傳輸和解碼的資料格式。

 

DER是ASN.1眾多編碼方案中的一個。

ASN.1 defines the abstract syntax of information but does not restrict the way the information is  encoded. Various ASN.1 encoding rules provide the transfer syntax (a  concrete representation) of the data values whose abstract syntax is  described in ASN.1.

The standard ASN.1 encoding rules include:

  • Basic Encoding Rules (BER)
  • Canonical Encoding Rules (CER)
  • Distinguished Encoding Rules (DER)
  • XML Encoding Rules (XER)
  • Packed Encoding Rules (PER)
  • Generic String Encoding Rules (GSER)

ASN.1 together with specific ASN.1 encoding rules facilitates the  exchange of structured data especially between application programs over networks by describing data structures in a way that is independent of  machine architecture and implementation language.

 

Application layer protocols such as X.400  electronic mail , X.500 and LDAP  directory services , H.323 (VoIP ), BACnet and SNMP use ASN.1 to describe the protocol data units (PDUs) they exchange. It is also extensively used in the Access and Non-Access Strata of UMTS . There are many other application domains of ASN.1 [ 1] .

 

A particularly useful new application of ASN.1 is Fast Infoset . Fast Infoset is an international standard that specifies a binary encoding format for the XML Information Set (XML Infoset ) as an alternative to the XML document format. It aims to provide more efficient serialization than the text-based XML format.

Example

Data structures of FooProtocol defined using the ASN.1 notation:

FooProtocol DEFINITIONS ::= BEGIN      FooQuestion ::= SEQUENCE {         trackingNumber INTEGER,         question       IA5String     }      FooAnswer ::= SEQUENCE {         questionNumber INTEGER,         answer         BOOLEAN     }  

This could be a specification published by creators of Foo protocol.  ASN.1 does not define conversation flows. This is up to the textual  description of the protocol.

Assuming a message, which complies with Foo protocol and which will be sent to the receiving party. This particular message (PDU ) is:

 myQuestion FooQuestion ::= {     trackingNumber     5,     question           "Anybody there?" }  

To send the above message through the network one needs to encode it to a string of bits . ASN.1 defines various algorithms to accomplish that task, called  Encoding rules. There are plenty of them; one of the simplest is Distinguished Encoding Rules (DER) .

The Foo protocol specification should explicitly name one set of  encoding rules to use, so that users of the Foo protocol know which one  they should use.

[edit ]  Example encoded in DER

Below is the data structure shown above encoded in the DER format (all numbers are in hexadecimal):

 

30 -- tag indicating SEQUENCE 13 -- length in octets  02 -- tag indicating INTEGER 01 -- length in octets 05 -- value  16 -- tag indicating IA5String 0e -- length in octets 41 6e 79 62 6f 64 79 20 74 68 65 72 65 3f -- value   

(Note: DER uses a pattern of tag-length-value triplets)

So what one actually gets is the string of 21 octets:

 

30 13 02 01 05 16 0e 41 6e 79 62 6f 64 79 20 74 68 65 72 65 3f 

The scope of ASN.1 and DER ends here. It is possible to transmit the encoded message to the party by any means (utilizing TCP or any other protocol). The party should be able to decode the octets back using DER.

("Anybody there?" in ASCII)

[轉] DER編碼和ASN.1

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.