16进制字符串转换成C语言的byte数组

@Test
    public void test(){

     String   rsa2048Rand = "1CF68745B5965DDDBB975BF6047BF15B242584C6BA7E5830BB5BACB33146BD8BD6493E552FD1325E5C426DD9C6A3695A";
        int length = rsa2048Rand.length()/2;
        String ss = "byte c[] = {";
        for (int i = 0; i < length; i++) {
            ss += "0x"+rsa2048Rand.substring(0,2);
            if( i < length-1) {
                ss += ", ";
            }
            rsa2048Rand = rsa2048Rand.substring(2);
        }

        ss += " }";

        System.out.println(" " + ss);

    }

其中 typedef unsigned char byte;

 byte c[] = {0x1C, 0xF6, 0x87, 0x45, 0xB5, 0x96, 0x5D, 0xDD, 0xBB, 0x97, 0x5B, 0xF6, 0x04, 0x7B, 0xF1, 0x5B, 0x24, 0x25, 0x84, 0xC6, 0xBA, 0x7E, 0x58, 0x30, 0xBB, 0x5B, 0xAC, 0xB3, 0x31, 0x46, 0xBD, 0x8B, 0xD6, 0x49, 0x3E, 0x55, 0x2F, 0xD1, 0x32, 0x5E, 0x5C, 0x42, 0x6D, 0xD9, 0xC6, 0xA3, 0x69, 0x5A }
 

你可能感兴趣的:(TPM,c语言,java,服务器)