PublicKey encoding in java map

How do I encode the ECDSA PublicKey on a Java card so that after I can decode it on another platform (for example, by sending the encoded key to the response APDU and processing it in a standard Java application)? keyPair.getPublic().getEncoded()

in Java will do the PKCS # 8 encoding trick, but getEncoded()

not available on Java Card platform as far as I know .

+2


source to share


2 answers


You can implement this function like this:

Map side:

  • 1 KeyPair.getPublicKey () → publicKey;
  • 2 publicKey.getW () → W;
  • 3 Send W to the street;


Standard side of java application:

  • 1 get data bytes W;
  • data bytes 2 W → ECPoint;
  • 3 Build PublicKey with ECPoint generated in step 2 uses the ECPublicKeySpec class;
  • 4 Use the public key in your application;
+4


source


getEncoded()

the method returns the key in its primary encoding format, or null if the key does not support encoding. Therefore, you don't need to use it for your purpose. you can just use down-casting to ECPublicKey

:

ECPublicKey pubKey = (ECPublicKey) keyPair.getPublic()

      



pubKey

in the above line equals the method output getEncoded()

in Java applications.

+1


source







All Articles