something wrong with TDES to encrypt data
Posted: Tue May 24, 2016 1:47 am
Recently, I have completed an applet, in which I use TDES to encrypt data.
But now I am stuck with a problem that I could not pass dofinal function.
Can anyone point what happened?
But now I am stuck with a problem that I could not pass dofinal function.
Can anyone point what happened?
Code: Select all
public void Encrypt3DES_CBC()
{
byte [] keydata = {(byte)0x11,(byte)0x11,(byte)0x11,(byte)0x11,(byte)0x11,(byte)0x11,(byte)0x11,(byte)0x11};
byte [] input = {(byte)0x22,(byte)0x22,(byte)0x22};
byte [] output = new byte [100];
Cipher m_encryptCipher;
DESKey m_desKey = (DESKey)KeyBuilder.buildKey(KeyBuilder.TYPE_DES, KeyBuilder.LENGTH_DES, false);
m_desKey.setKey(keydata,(short)0);
m_encryptCipher = Cipher.getInstance(Cipher.ALG_DES_CBC_ISO9797_M1, false);
m_encryptCipher.init(m_desKey,Cipher.MODE_ENCRYPT);
m_encryptCipher.doFinal(input,ISO7816.OFFSET_CDATA,(short)input.length,output,(short)0);
}