Encode publicKey on Java Card

2019-04-12 16:10发布

How to encode an ECDSA PublicKey on Java Card so that after I can decode it on another platform (e.g. sending the encoded key in a response APDU and processing it in a standard Java application)? keyPair.getPublic().getEncoded() on Java would do the trick with PKCS#8 encoding, but as far as I know getEncoded() is not available on the Java Card platform.

2条回答
姐就是有狂的资本
2楼-- · 2019-04-12 16:38

getEncoded() method returns the key in its primary encoding format, or null if the key does not support encoding. So you don't need to use it for your goal. you simply can use down-casting to ECPublicKey:

ECPublicKey pubKey = (ECPublicKey) keyPair.getPublic()

The pubKey in the above line, is equal with output of getEncoded() method in Java applications.

查看更多
不美不萌又怎样
3楼-- · 2019-04-12 16:50

You can implement this function like this:

Card side:

  • 1 KeyPair.getPublicKey() --> publicKey;
  • 2 publicKey.getW() --> W;
  • 3 Send W to outside;

Standard java application side:

  • 1 get W data bytes;
  • 2 W data bytes --> ECPoint;
  • 3 Build PublicKey with the ECPoint generated in step 2 use the class ECPublicKeySpec;
  • 4 Use the public key in your application;
查看更多
登录 后发表回答