[英]How do I encrypt and send DES key with RSA private key and then public key in Java?
[英]How can I send my public key in an APDU (Javacard)?
我正在尝试在 APDU 中从我的密钥对发送我的公钥,以便可以在另一个程序中验证签名。 到目前为止,我还没有找到将密钥放入 APDU 缓冲区的方法。
我在网上找到了使用RSAPublicKey.getExponent()
将密钥存储在字节数组中(然后将其添加到缓冲区)的解决方案,但是由于我没有使用 RSAPublicKey,所以这并没有那么有用。 这是唯一的方法吗? 我是否需要使用 RSAPublicKey 而不是密钥对,或者是否有某种方法可以将我的密钥对中的公钥放入 APDU 缓冲区?
这是我的密钥生成代码:
KeyPair key = new KeyPair(KeyPair.ALG_RSA, (short)5120);
key.genKeyPair();
首先,RSA公钥由模数和指数组成。 首先,您需要使用 getPublic() 并恢复具有 RSAPublicKey 接口的 object,该接口公开 getExponent 和 getModulus 方法,这些方法将为您提供可以放入 APDU 缓冲区的字节 arrays。 公共指数可能类似于 0x010001,但模数将是您声明为 KeyPair 参数的位长度。
对于如此长的模数,您将需要扩展 APDU 或将其拆分为多个 APDU 交换。 为了兼容性,我通常会推荐第二种方法,但如果您正在处理的系统肯定会在两端处理扩展 APDU,您可以尝试在一个 go 中执行此操作。
我面前没有有效的 JavaCard IDE 但类似的东西应该可以工作:
KeyPair keyPair = new KeyPair(KeyPair.ALG_RSA, (short)xxx);
keyPair.genKeyPair();
RSAPublicKey pubKey = (RSAPublicKey) keyPair.getPublicKey();
short len = pubkey.getExponent(apdu.getBuffer(), (short)0);
并从这里继续...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.