IllegalBlockSizeException when .jar compiled into .NET dll
2 Message(s) by 2 Author(s) originally posted in java programmer
| From: javadev |
Date: Sunday, October 21, 2007
|
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 not 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
bit Count = 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
| From: =?ISO-8859-1?Q?Arne_Vajh=F8j?= |
Date: Saturday, October 27, 2007
|
wrote in message:
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 not 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
Next Message: j2ee JAVA Blueprints package/directory structure: best practice for common code?
Blogs related to IllegalBlockSizeException when .jar compiled into .NET dll
IllegalBlockSizeException when .jar compiled into .NET dll
comp.lang.
java.programmer:
IllegalBlockSizeException when .jar compiled into .NET dll.