您好我目前得到的問題,我想創建一個X509證書序列號的表示,該證書完全匹配.crt文件中的十六進制表示形式。爲了得到這種感覺,我創建了一些證書和翻譯的BigInteger表示爲十六進制是這樣的:determinien前導零在序列號
public static String toHex (String number) {
BigInteger toHex = new BigInteger(number, 10);
String hex = toHex.toString(16);
if (hex.trim().length()%2 == 1) {
hex = "0" + hex;
}
hex = hex.replaceAll("(?<=..)(..)", " $1");
return hex;
}
我現在的問題是,這並不在所有的工作。我發現至少有一個序列號表示,其中的代碼失敗:
BigInteger: 186553134784695772803573402931138131429
Hex from .crt: 00 8c 58 d3 ac 72 fc 2f 17 70 cd 17 a5 07 d3 f5 e5
有2個前導零,我想不通爲什麼和在什麼情況下添加這些前導零。有人能幫助我嗎?
P.s .:我不想刪除我真正想要添加它們的前導零。
我得到''8c 58 d3 ac 72 fc 2f 17 70 cd 17 a5 07 d3 f5 e5'' – agad