Page 1 of 1

Generate a key based on a byte array

Posted: Sun Jul 17, 2016 11:19 pm
by Usiger
There is a PIN in my applet, which is needed to encrypt by 3DES. I have a byte array "pw_ar" and I want to generate a key for 3DES algorithm based on this array. How can I do this? Thanks! Any reply is appreciated!

Note: my javacard version is JC2.1.1

Re: Generate a key based on a byte array

Posted: Mon Jul 18, 2016 3:46 am
by wousim
View the below screenshot from java card API 3.0.4



DESKey contains an 8/16/24-byte key for single/2 key triple DES/3 key triple DES operations.


For example:
If you want to use 3 key 3DES: You will need a 24 byte array containing some data related to your password. You should use a message digest function (sha, md5 etc) and hash your password. This will generate you a digest. From this digest you take the first 24 bytes, which you can use as your 3DES key.