如何在JavaSpring中实现ASN1解码?
How to implement ASN1 decoding in Java Spring?
我需要从一个复杂的序列中解码 ASN1 字符串,但我无法弄清楚这一切是如何工作的。我想做类似
的事情
decoder = ASN1Library.initWithSequence(sequenceString);
ParseObject obj = decoder.decodeString(asn1String);
我尝试了一些库,但 none 允许我做我想做的,或者我无法理解它们是如何工作的。我想我需要自己实现一个解析器。
任何人都可以解释如何这样做吗?
非常感谢!
好的,这就是我的发现。
我正在使用 com.objsys.asn1j.runtime
库;我需要在 Java classes 中实现整个序列,并使每个 class 扩展 Asn1Seq
、Asn1Integer
或其他超级 classes图书馆。
在扩展 Asn1Seq 的每个 class 中(即所有类似序列的 classes)我需要覆盖 decode
方法并且在正文中我必须再次调用 decode
class.
的每个属性
快速示例(Type1
和 Type2
扩展 Asn1Integer
):
class SeqData extends Asn1Seq {
private static final long serialVersionUID = 55L;
Type1 attribute1;
Type2 attribute2;
@Override
public int getElementCount() {
return 2;
}
@Override
public String getElementName(int arg0) {
switch (arg0) {
case 0:
return "attribute1";
case 1:
return "attribute2";
}
return "";
}
@Override
public Object getElementValue(int arg0) {
switch (arg0) {
case 0:
return attribute1;
case 1:
return attribute2;
}
return null;
}
@Override
public void decode(Asn1PerDecodeBuffer arg0) throws Asn1Exception, IOException {
attribute1 = new Type1();
attribute1.decode(arg0, 1L, 62L);
attribute2 = new Type2();
attribute2.decode(arg0, 1L, 62L);
}
我需要从一个复杂的序列中解码 ASN1 字符串,但我无法弄清楚这一切是如何工作的。我想做类似
的事情decoder = ASN1Library.initWithSequence(sequenceString);
ParseObject obj = decoder.decodeString(asn1String);
我尝试了一些库,但 none 允许我做我想做的,或者我无法理解它们是如何工作的。我想我需要自己实现一个解析器。
任何人都可以解释如何这样做吗? 非常感谢!
好的,这就是我的发现。
我正在使用 com.objsys.asn1j.runtime
库;我需要在 Java classes 中实现整个序列,并使每个 class 扩展 Asn1Seq
、Asn1Integer
或其他超级 classes图书馆。
在扩展 Asn1Seq 的每个 class 中(即所有类似序列的 classes)我需要覆盖 decode
方法并且在正文中我必须再次调用 decode
class.
快速示例(Type1
和 Type2
扩展 Asn1Integer
):
class SeqData extends Asn1Seq {
private static final long serialVersionUID = 55L;
Type1 attribute1;
Type2 attribute2;
@Override
public int getElementCount() {
return 2;
}
@Override
public String getElementName(int arg0) {
switch (arg0) {
case 0:
return "attribute1";
case 1:
return "attribute2";
}
return "";
}
@Override
public Object getElementValue(int arg0) {
switch (arg0) {
case 0:
return attribute1;
case 1:
return attribute2;
}
return null;
}
@Override
public void decode(Asn1PerDecodeBuffer arg0) throws Asn1Exception, IOException {
attribute1 = new Type1();
attribute1.decode(arg0, 1L, 62L);
attribute2 = new Type2();
attribute2.decode(arg0, 1L, 62L);
}