如何在Java中将证书指纹字符串转换为字节数组?

发布于 2025-01-18 15:19:52 字数 664 浏览 6 评论 0原文

我的程序要求用户输入证书指纹字符串,然后将输入转换为字节数组以供以后使用。 我要问的是,如何将inputStringArray转换为contrestresult字节数组?

String input = "2F:A3:CF:8F:D6:ED:06:79:B8:FB:DB:0E:3B:A4:52:45:83:8E:7F:C5";
String[] inputStringArray = input.trim().split(":");

//convert inputStringArray to results array here
//...

byte[] convertResult = new byte[]
                {(byte)0x2f, (byte)0xa3, (byte)0xcf, (byte)0x8f, (byte)0xd6, (byte)0xed, (byte)0x06, (byte)0x79, (byte)0xb8, (byte)0xfb,
                        (byte)0xdb, (byte)0x0e, (byte)0x3b, (byte)0xa4, (byte)0x52, (byte)0x45, (byte)0x83, (byte)0x8e, (byte)0x7f, (byte)0xc5};


谢谢!

My program asks user to input a string of certificate fingerprint then convert the input to byte array for later use.
What I am asking is how should I convert the inputStringArray to the convertResult byte array?

String input = "2F:A3:CF:8F:D6:ED:06:79:B8:FB:DB:0E:3B:A4:52:45:83:8E:7F:C5";
String[] inputStringArray = input.trim().split(":");

//convert inputStringArray to results array here
//...

byte[] convertResult = new byte[]
                {(byte)0x2f, (byte)0xa3, (byte)0xcf, (byte)0x8f, (byte)0xd6, (byte)0xed, (byte)0x06, (byte)0x79, (byte)0xb8, (byte)0xfb,
                        (byte)0xdb, (byte)0x0e, (byte)0x3b, (byte)0xa4, (byte)0x52, (byte)0x45, (byte)0x83, (byte)0x8e, (byte)0x7f, (byte)0xc5};


Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你在我安 2025-01-25 15:19:53

回答我自己的问题:

public static byte[] str2bytes(String input) {
        String [] hex_list = input.split(":");
        byte[] output = new byte[hex_list.length];
        int i = 0;
        for (String hex: hex_list) {
            output[i] = (byte) Integer.parseInt(hex, 16);
            i ++;
        }
        return output;
    }

answer to my own question:

public static byte[] str2bytes(String input) {
        String [] hex_list = input.split(":");
        byte[] output = new byte[hex_list.length];
        int i = 0;
        for (String hex: hex_list) {
            output[i] = (byte) Integer.parseInt(hex, 16);
            i ++;
        }
        return output;
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文