簡體   English   中英

Java - 將十六進制字符串解析為 ASN.1 格式

[英]Java - Parsing Hex String to ASN.1 Format

我試圖將我的十六進制字符串解碼為 ASN.1 結構(標簽 - 長度 - 值),就像這個頁面: https://asn1.io/asn1playground/但我被 Bouncy Castle 庫困住了。 有什么方法可以解決我的問題嗎?

My hex string values = "100101110D48434D432D46492D30312D3031120131130130010A464930303030303030331D0614050D0A3A04"

我需要像這樣的解碼結果:

tag 1: 10 - lenght 1: 01 - value 1: 01
tag 2: 11 - lenght 2: 0D - value 2: 48434D432D46492D30312D3031
tag 1: 12 - lenght 1: 01 - value 1: 31
...

您可以使用我的運行時庫的源代碼(並對其進行修改以達到您想要的確切結果)

現在它是這樣工作的:

1/ 從https://github.com/yafred/asn1-tool/releases下載 asn1-runtime.jar

2/ 在類路徑中使用 asn1-runtime.jar 編譯 class

package asn1;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.PrintWriter;

import com.yafred.asn1.runtime.BERDumper;

public class Dump {

    public static void main(String[] args) throws IOException {
        String values = "100101110D48434D432D46492D30312D3031120131130130010A464930303030303030331D0614050D0A3A04";


        // dump TLV form
        ByteArrayInputStream bufferIn = new ByteArrayInputStream(BERDumper.bytesFromString(values));
        new BERDumper(new PrintWriter(System.out)).dump(bufferIn);

    }

}

3/ 運行它(使用 asn1-runtime.jar)

T: 10 (PRIMITIVE_UNIVERSAL_16)
L: 1
V: 01
T: 11 (PRIMITIVE_UNIVERSAL_17)
L: 13
V: 48 43 4d 43 2d 46 49 2d 30 31 2d 30 31
T: 12 (PRIMITIVE_UNIVERSAL_18)
L: 1
V: 31
T: 13 (PRIMITIVE_UNIVERSAL_19)
L: 1
V: 30
T: 01 (PRIMITIVE_UNIVERSAL_1)
L: 10
V: 46 49 30 30 30 30 30 30 30 33
T: 1d (PRIMITIVE_UNIVERSAL_29)
L: 6
V: 14 05 0d 0a 3a 04

如果你沒有找到其他東西,這可能是一個好的開始......

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM