However I don't know how to generate a DESKey if I don't set it by myself.
My code is as belows. In this case, I gor error SW_UNINITIALIZED_KEY. Is there any solution to solve this problem.
Code: Select all
DESKey tdesKey;
Cipher desCipher;
byte[] ENC_RESULT;
// Set DESKey by myself
//byte[] KeyEnc ={(byte)0x51, (byte)0xF5, (byte)0x64, (byte)0x86, (byte)0xE5,(byte)0x04, (byte)0xD6, (byte)0x28,(byte)0x01, (byte)0x45, (byte)0x2A, (byte)0x13, (byte)0x04,(byte)0xE2, (byte)0x5F, (byte)0x7B};
tdesKey = (DESKey) KeyBuilder.buildKey(KeyBuilder.TYPE_DES, KeyBuilder.LENGTH_DES3_2KEY, true);
//tdesKey.setKey(KeyEnc, (short) 0);
desCipher = Cipher.getInstance(Cipher.ALG_DES_ECB_NOPAD, false);
desCipher.init(tdesKey, Cipher.MODE_ENCRYPT);
desCipher.doFinal(Data, (short) 0, (short) Data.length, ENC_RESULT, (short) 0);