【发布时间】:2017-09-26 20:49:35
【问题描述】:
我正在使用 Bouncy Castle 解码 BER X.690 ASN.1 文件。
这是 ASN.1 映射文件的一部分:
CallEventRecord ::= CHOICE
{
sgsnPDPRecord [20] SGSNPDPRecord,
}
SGSNPDPRecord ::= SET
{
recordType [0] CallEventRecordType,
networkInitiation [1] NetworkInitiatedPDPContext OPTIONAL,
servedIMSI [3] IMSI,
servedIMEI [4] IMEI OPTIONAL
}
我能够成功地从输入文件中读取对象。并在 BERTaggedObject berObj 上调用 toString 方法给出:
[20][[0]#12, [3]#12191031148270f3, [4]#5302816004686062,]
你可以看到SGSNPDPRecord的标签[20],[0]#12是recordType和它的内容,这里一切都做得很好我用ASN1 Dump Utility检查了它。
我一直在提取SGSNPDPRecord 成员字段(recordType、networkInititation 等)。
我不确定如何从BERTaggedObjectberObj 中提取字段及其 berTag。
public class SGSNPDPRecord extends ASN1Object
{
Integer recordType;
Boolean networkInitiation;
String servedIMSI;
String servedIMEI;
private static int SGSNPDP_RECORD_BER_TAG = 20;
public SGSNPDPRecord(BERTaggedObject berObj) throws IOException {
int tagNo = berObj.getTagNo();
// Returns tag number 20, this one is OK
if (tagNo != SGSNPDP_RECORD_BER_TAG )
{
System.out.println("Invalid Tag Number!");
return;
}
// How to get here someObject that will check BER Tags of primitive fields recordType, networkInitiation ... and read content from the specific ber tag
switch ( someObj.getApplicationTag() )
{
case 0:
this.recordType = new Integer( someObj.getContents()[0] );
break;
case 1:
this.networkInitiation = new Boolean(new String( someObj.getContents()[0], "UTF-8"));
break;
case 3:
this.servedIMSI = new String(someObj.getContents(), "UTF-8");
break;
case 4:
this.servedIMEI = new String(someObj.getContents(), "UTF-8");
break;
default:
break;
}
}
@Override
public ASN1Primitive toASN1Primitive()
{
return null;
}
}
【问题讨论】:
-
能否提供输入文件?
-
很遗憾,我不能给你整个文件,因为它有私人数据编码。我可以给它一个开始。 B4 80 80 01 12 83 08 12 19 10 31 92 58 95 F0 84 08 53 34 40 80 21 83 89 20 00 00 ,此序列将等于 berTags 0、3 和 4(recordType、servedIMSI、servedIMEI)。用于编码未定义的长度。内容结尾八位字节出现在普通的 00 和 00 分别作为标识符和长度八位字节出现的地方。长度八位字节。一个八位字节,80。
标签: java bouncycastle asn.1