解读TPM工具tpm_getpubek输出(Interpreting tpm-tools tpm_g

2019-09-28 03:32发布

tpm_getpubek的输出是下面的形式: http://trousers.sourceforge.net/man/tpm_getpubek.8.html

Key Size:          2048 bits
Public Key:

be262286 b51d0a21 88860ae7 32db7478 503c9213 bbb5545a 7e5d7c5f 30ff83da
37c5b548 fee21fd1 650181e8 3401a86b 1462e94e 118fc7f3 eb976b4c eb3a091f
6c5ea72c 527711dc ffbf1ae5 51fcbe1a aec95c64 7e2ac0eb 93484551 339f4959
6332b500 024cfe5c e08697cb 7431b3f4 328b4569 5e2e3eed 93a962d9 8387a58c
df15ecd1 9d01dd08 e2e60002 2baa6197 485dfbfc dd2f1898 fdff3913 7cc3bdc1
cc8bcb04 19e26ac8 466b6daf 4d53e9ea 88e45364 d029c1af b035a354 0f2e4484
e51bc0aa d216cdb6 71f50abb 44a0fdba 38715a6c 0c97d45d 5f3c08ab e7a46117
3666e6b0 d840ee54 4c617388 1714f0a1 acded3bd fc3ea323 8e7d1fcb 9fe74340

1)我有一个艰难的时间来了解如何使用它。 我试图将其转换为通过代码的Java对象公钥:

byte[] derPublicKey = DatatypeConverter.parseHexBinary(keyBloc);
X509EncodedKeySpec x509publicKey = new X509EncodedKeySpec(derPublicKey);
KeyFactory factory = KeyFactory.getInstance("RSA");
PublicKey publicKey = factory.generatePublic(x509publicKey);

但是,这将返回以下错误:

java.security.spec.InvalidKeySpecException: java.security.InvalidKeyException: invalid key format
at sun.security.rsa.RSAKeyFactory.engineGeneratePublic(RSAKeyFactory.java:205)
 [java]     at java.security.KeyFactory.generatePublic(KeyFactory.java:334)

Answer 1:

tpm_getpubek返回其原始形式,而不是一个X509编码的blob十六进制编码的公共密钥的模量。 假设你保存了返回的数据到一个名为字符串keyBlock (有空格去掉),你会产生这样的公共密钥:

PublicKey pk = KeyFactory.getInstance("RSA").generatePublic(
    new RSAPublicKeySpec(new BigInteger(keyBlock, 16), new BigInteger("65537")));


文章来源: Interpreting tpm-tools tpm_getpubek output
标签: java tpm