我正在使用完整性测量架构 (IMA) ( https://sourceforge.net/p/linux-ima/wiki/Home/ ) 并且我正在尝试用 Java 编写他们已经在 C 中完成并在上面的链接页面。
从测量列表开始:
PCR-00: 07274edf7147abda49200100fd668ce2c3a374d7
PCR-01:48dff4fbf3a34d56a08dfc1504a3a9d707678ff7
PCR-02:53de584dcef03f6a7dac1a240a835893896f218d
PCR-03:3a3f780f11a4b49969fcaa80cd6e3957c33b2275
PCR-04:acb44e9dd4594d3f121df2848f572e4d891f0574
PCR-05:df72e880e68a2b52e6b6738bb4244b932e0f1c76
PCR-06: 585e579e48997fee8efd20830c6a841eb353c628
PCR-07:3a3f780f11a4b49969fcaa80cd6e3957c33b2275
我需要计算所有这些测量值的总和。执行此操作的 C 代码是:
SHA1_Init(&c);
for (i = 0; i < NUM_PCRS; i++) {
if (DEBUG) {
printf("PCR-%2.2x: ", i);
display_sha1_digest(pcr[i].digest);
}
SHA1_Update(&c, pcr[i].digest, 20);
}
SHA1_Final(boot_aggregate, &c);
使用此代码的结果是:b5a166c10d153b7cc3e5b4f1eab1f71672b7c524
我写了这个java行来做到这一点:
String pcr0 = "07274edf7147abda49200100fd668ce2c3a374d7";
String pcr1 = "48dff4fbf3a34d56a08dfc1504a3a9d707678ff7";
String pcr2 = "53de584dcef03f6a7dac1a240a835893896f218d";
String pcr3 = "3a3f780f11a4b49969fcaa80cd6e3957c33b2275";
String pcr4 = "acb44e9dd4594d3f121df2848f572e4d891f0574";
String pcr5 = "df72e880e68a2b52e6b6738bb4244b932e0f1c76";
String pcr6 = "585e579e48997fee8efd20830c6a841eb353c628";
String pcr7 = "3a3f780f11a4b49969fcaa80cd6e3957c33b2275";
MessageDigest hash = MessageDigest.getInstance("SHA-1");
byte[] firstToLastDigest;
hash.reset();
hash.update(pcr0.getBytes("UTF-8"));;
hash.update(pcr1.getBytes("UTF-8"));
hash.update(pcr2.getBytes("UTF-8"));
hash.update(pcr3.getBytes("UTF-8"));
hash.update(pcr4.getBytes("UTF-8"));
hash.update(pcr5.getBytes("UTF-8"));
hash.update(pcr6.getBytes("UTF-8"));
hash.update(pcr7.getBytes("UTF-8"));
firstToLastDigest = hash.digest();
digestStr = javax.xml.bind.DatatypeConverter.printHexBinary(firstToLastDigest);
System.out.println(digestStr);
但我得到的是“EA3487AC70DC445A2E608ED44DC550366F2C6716”而不是预期的结果:“b5a166c10d153b7cc3e5b4f1eab1f71672b7c524”。有什么建议吗?