Hello all
I had posted this query a few days back on the
comp.java.lang.programmer group and after trying a few things I still
am facing the problem of IllegalBlockSizeException being thrown from
the .NET dll that I have compiled with the message - "1 trailing
bytes".
Following is the link to the earlier post:
http://groups.google.co.in/group/comp.lang.java.programmer/browse_thread/thread/
dfa5d6d5bd7cd5fe?hl=en
Since then I have changed my key to an 8 byte array just in case the
conversion from the String and the adding of parity bits was causing
problems and hence my code now is:
Cipher ecipher = Cipher.getInstance("DES");
byte[] raw = {0x0051, 0x0041, 0x003C, 0x003A, 0x0041, 0x0050, 0x0033,
0x003D};
SecretKey mySpec = new SecretKeySpec(result, "DES");
ecipher.init(Cipher.ENCRYPT_MODE, mySpec);
byte[] utf8 = "encryptThis".getBytes("UTF8");
byte[] enc = ecipher.doFinal(utf8); // IllegalBlockSizeException here
However, I still get the same IllegalBlockSizeException error with the
message - "1 trailing bytes" and I would like to know if there is a
workaround to this solution as I am now stuck and cannot think of
anything else that I can do. Any ideas will be appreciated.
Thanks
Swetha
swetha - 24 Oct 2007 12:03 GMT
Apparently, changing
Cipher ecipher = Cipher.getInstance("DES");
to
Cipher ecipher = Cipher.getInstance("DES/ECB/PKCS5Padding");
works.