Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2007

Tip: Looking for answers? Try searching our database.

IllegalBlockSizeException when .jar compiled into .NET dll

Thread view: 
javadev - 21 Oct 2007 08:17 GMT
Hello all

I have the following piece of code as part of my .jar file which is
then compiled into a .NET dll using IKVM. The code runs fine when run
as a jar but on using the .NET dll I receive an
IllegalBlockSizeException. Apparently the conversion into the dll is
causing the error, but I can't figure out what I need to do work
around this problem. Any help will be greatly appreciated.

Cipher ecipher = Cipher.getInstance("DES");
byte[] raw = "SOMESTR".getBytes();
byte[] result = new byte[8];
int resultIx = 1;
int bitCount = 0;

for(int i = 0; i < 56; i++)
{
boolean bit = (in[6 - i/8]&(1 << (i%8))) > 0;

if(bit)
{
result[7 - resultIx/8] |= (1 << (resultIx % 8)) & 0xFF;
bitCount++;
}
if((i + 1) % 7 == 0)
{
if(bitCount % 2 == 0)
result[7 - resultIx/8] |= 1;
resultIx++;
bitCount = 0;
}
resultIx++;
}

SecretKey mySpec = new SecretKeySpec(result, "DES");
ecipher.init(Cipher.ENCRYPT_MODE, mySpec);

byte[] utf8 = "encryptThis".getBytes("UTF8");
byte[] enc = ecipher.doFinal(utf8); // IllegalBlockSizeException here
Arne Vajhøj - 27 Oct 2007 18:22 GMT
> I have the following piece of code as part of my .jar file which is
> then compiled into a .NET dll using IKVM. The code runs fine when run
> as a jar but on using the .NET dll I receive an
> IllegalBlockSizeException. Apparently the conversion into the dll is
> causing the error, but I can't figure out what I need to do work
> around this problem. Any help will be greatly appreciated.

> Cipher ecipher = Cipher.getInstance("DES");

> ecipher.init(Cipher.ENCRYPT_MODE, mySpec);
>
> byte[] utf8 = "encryptThis".getBytes("UTF8");
> byte[] enc = ecipher.doFinal(utf8); // IllegalBlockSizeException here

IKVM is a very cool tool, but it is in no way supported !

Try encrypt a string that is a multipla of 8.

If that works then try:

Cipher.getInstance("DES/ECB/PKCS5Padding")

Arne
swetha - 01 Nov 2007 08:31 GMT
On Oct 27, 8:22 pm, Arne Vajh?j <a...@vajhoej.dk> wrote:

> IKVM is a very cool tool, but it is in no way supported !
>
[quoted text clipped - 3 lines]
>
> Cipher.getInstance("DES/ECB/PKCS5Padding")

I mailed the IKVM forums about some days back and yes, the "DES/ECB/
PKCS5Padding" was what they had suggested and it worked fine for me.
Thanks.
Roedy Green - 03 Nov 2007 18:02 GMT
>SecretKey mySpec = new SecretKeySpec(result, "DES");
>ecipher.init(Cipher.ENCRYPT_MODE, mySpec);
>
>byte[] utf8 = "encryptThis".getBytes("UTF8");
>byte[] enc = ecipher.doFinal(utf8); // IllegalBlockSizeException here

you have used a 256 -bit key. I would suspect that freaks the
Fatherland Security people who want to snoop on everything you do. Try
giving it a 56 bit key and see what happens.
Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.