Our Online Store have the new products: RFID antenna board. Currently it can work with JC10M24R and JCOP4 card chips.
Compared with normal cards, the antenna board module has a smaller size and fixed holes, which is easy to integrate in the IOT(Internet Of Things) project.

How to use keyBuilder class

JavaCard Applet Development Related Questions and Answers.
Methen
Posts: 5
Joined: Wed Dec 21, 2016 11:44 pm
Points :80
Contact:

How to use keyBuilder class

Post by Methen » Mon Jan 23, 2017 4:24 am

Hi all. I have to simulate DDA authentication for my project. I placed my private and public keys inside byte[] variables in applet, and in order to encrypt and decrypt messages, I should convert these byte arrays to PublicKey and PrivateKey objects. javacard.security defines a key factory class keyBuilder, but I don't know how to use this class, to reconstruct my keys, which are in byte array. Does anyone know this?

User avatar
UNKNwYSHSA
Posts: 630
Joined: Thu May 21, 2015 4:05 am
Points :3053
Contact:

Re: How to use keyBuilder class

Post by UNKNwYSHSA » Mon Jan 23, 2017 5:19 am

You can use like following (This is sample of RSAPublicKey)

Code: Select all

// Create one key instance;
RSAPublicKey rsaPuKey = (RSAPublicKey) KeyBuilder.buildKey(KeyBuilder.TYPE_RSA_PUBLIC, keysize, false);
// Set key value with key value bytes: rsa public key N;
rsaPuKey.setModulus(modulusBuffer, modulusOffset, modulusLength);
// Set key value with key value bytes: rsa public key E;
rsaPuKey.setExponent(exponentBuffer, exponentOffset, exponentLength);
// You can use the key now ...
sense and simplicity

User avatar
mabel
Posts: 237
Joined: Mon May 18, 2015 3:09 am
Points :1705
Contact:

Re: How to use keyBuilder class

Post by mabel » Tue Jan 24, 2017 4:01 am

It's recommended to keep keys in Key objects than in arrays, because keys can be protected by the underlying platform, but arrays cannot.

choimillen
Posts: 30
Joined: Wed Aug 19, 2015 2:55 am
Points :213
Contact:

Re: How to use keyBuilder class

Post by choimillen » Tue Jan 24, 2017 4:07 am

Build a key using keybuilder methods and cast:

RSAPublicKey k1 = (RSAPublicKey)KeyBuilder.buildKey(KeyBuilder.TYPE_RSA_PUBLIC, KeyBuilder.LENGTH_RSA_1024);

Then, use:
k1.setExponent(bytearray, offsettoexponent);
k1.setModulus(bytearray, offsettomodulus);

k1.getExponent(destination, wheretostore);
...

Same for others.

Post Reply Previous topicNext topic

Who is online

Users browsing this forum: No registered users and 59 guests

JavaCard OS : Disclaimer