String Res[][]={{"af","ea","ff","ea"},
{"ea","ba","cc","aa"},
{"aa","cb","bc","cc"},
{"0a","ad","da","ff"}};
我正在实现AES 128位密钥。而解密我得到4乘4矩阵的十六进制值。如何将其转换为字符串?
答案 0 :(得分:0)
如果你想要这样的东西“afeaffeaeabaccaaaacbbccc0aaddaff”,那就是:
String Res[][]={{"af","ea","ff","ea"},
{"ea","ba","cc","aa"},
{"aa","cb","bc","cc"},
{"0a","ad","da","ff"}};
StringBuilder strBldr = new StringBuilder();
for(String[] ar : Res) {
for(String str : ar) {
strBldr.append(str);
}
}
System.out.println(strBldr.toString());
如果您打算将其转换为字符,可以在循环中替换:
strBldr.append((char) Integer.parseInt(str, 16));
假设字符由一个字节表示。如果没有,请参阅前。这个:http://ideone.com/kg2ZN5