解释tpm-tools tpm_getpubek输出 [英] Interpreting tpm-tools tpm_getpubek output

查看:232
本文介绍了解释tpm-tools tpm_getpubek输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

tpm_getpubek的输出格式为: http://trousers.sourceforge.net/man/tpm_getpubek.8.html

The output of tpm_getpubek is of the form: 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 PublicKey对象:

1) I am having a hard time to understand how to use it. I am trying to convert it to a java PublicKey object via the code:

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)

推荐答案

tpm_getpubek返回原始格式的十六进制编码的公钥模数,而不是X509编码的Blob.假设您将返回的数据保存到名为keyBlock的字符串中(删除了空格),您将生成如下所示的公钥:

tpm_getpubek returns the hex-encoded public key modulus in its raw form, not an X509 encoded blob. Assuming you saved the returned data into a string called keyBlock (with whitespace removed) you would generate the public key like this:

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

这篇关于解释tpm-tools tpm_getpubek输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆