JavacardOS will not accept order any more, please contact our partner Feitian online Store:
https://ftsafe.en.alibaba.com/index.html
https://ftsafe.en.alibaba.com/index.html
How to use keyBuilder class
How to use keyBuilder class
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?
- UNKNwYSHSA
- Posts: 630
- Joined: Thu May 21, 2015 4:05 am
- Points :3055
- Contact:
Re: How to use keyBuilder class
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
Re: How to use keyBuilder class
It's recommended to keep keys in Key objects than in arrays, because keys can be protected by the underlying platform, but arrays cannot.
-
- Posts: 30
- Joined: Wed Aug 19, 2015 2:55 am
- Points :213
- Contact:
Re: How to use keyBuilder class
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.
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.
Who is online
Users browsing this forum: No registered users and 24 guests