03-21-2010 08:06 PM
I'm in the midst of converting a BB SSH app to use the native BB crypto API instead of the custom code it currently uses. The work is nearly done, but I have run into a snag.
In the code below, new CBCEncryptor is throwing an IllegalArgumentException. Does anyone have any thoughts? The basic background:
function setupCrypto(byte[] IVc2s, byte[] Ec2s){
try {
TripleDESKey keyDe = new TripleDESKey(Es2c);
InitializationVector iv= new InitializationVector(IVs2c);
TripleDESDecryptorEngine tripleDESDecryptor = new TripleDESDecryptorEngine(keyDe);
// Exception thrown on this line.
BlockDecryptorEngine encryptor = new CBCDecryptorEngine(tripleDESDecryptor, ivdecrypt);
} catch (CryptoException ex) {
// doing something here
}
}
03-21-2010 11:27 PM
Something about this suggests that there is a mix-up somewhere between encryption and decryption code. The variables passed to new TripleDESKey() and new InitializationVector() aren't defined in your comments or the code. Are you sure that what you posted is what's executing?
Is there any message with the IllegalArgumentException?
03-22-2010 04:44 AM
My 3DES is a bit rusty, but shouldn't the key length be 192 bit and the IV length be 64 bit?
03-22-2010 09:33 PM
Thanks for the replies so far.
Ted_Hopp: I did confirm that everything is passed in correctly - the IV and key data are populated and are not in any way reversed. Unfortunately, there's no accompanying message with the IllegalArgumentException.
Iklyubin : believe it will ignore anything extra in this case.
Now - I was able to get this working, by shuffling things around a bit:
BlockEncryptorEngine ee = EncryptorFactory.getBlockEncryptorEngine(key,
"TripleDES", iv);
BlockEncryptorEngine encrypt = new CBCEncryptorEngine(ee);
And this does work without any issues.
When I previously tried to use EncrpytorFactory and failed, usage was as follows:
BlockEncryptorEngine ee = EncryptorFactory.getBlockEncryptorEngine(key,
"TripleDES");
BlockEncryptorEngine encrypt = new CBCEncryptorEngine(ee, iv);
So - while the change above does resolve the issue, I'm still going to leave the question open in case someone has any insights as to why the CBC engine can't accept the IV, but the DES engine can.