简体   繁体   中英

Parse ASN.1 encoding using Java

How can I read an ASN.1 file using Java when the file has this syntax and with .air file extension not .asn file extension

Tagged[6]IMPLICIT
 Sequence
  Tagged[0]IMPLICIT
   OCTET STRING[3](UGW)
  Tagged[1]IMPLICIT
   OCTET STRING[5](nair1)
  Tagged[3]IMPLICIT
   OCTET STRING[13](6430408182034)
  Tagged[5]IMPLICIT
   OCTET STRING[19](201211113336+0300)
  Tagged[6]IMPLIIT
   OCTET STRING[5](nair1)

ASN.1 definition of yours looks mistaken. I would suggest correcting it as below :

My-Schema DEFINITIONS IMPLICIT TAGS ::= 
BEGIN
  MySequence ::= SEQUENCE       
  {                                                     
     str1      OCTET STRING (SIZE(1..50)),
     str2      OCTET STRING (SIZE(1..50)),
     str3      OCTET STRING (SIZE(1..50)),
     str4      OCTET STRING (SIZE(1..50)),
     str5      OCTET STRING (SIZE(1..50))
   }                                                     
END

It can be easily encoded using bountycastle ASN.1 API

import org.bouncycastle.asn1.*;

    ASN1EncodableVector v = new ASN1EncodableVector();
    v.add(new DEROctetString("str1".getBytes()));
    v.add(new DEROctetString("str2".getBytes()));
    v.add(new DEROctetString("str3".getBytes()));
    v.add(new DEROctetString("str4".getBytes()));

    byte[] encoded = new DERSequence(v).getEncoded();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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