public static String encryptedAES(String text, String key, String iv) {
SecretKeySpec keyspec = new SecretKeySpec(key.getBytes(), "AES");
IvParameterSpec ivspec = new IvParameterSpec(iv.getBytes());
try {
Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");
cipher.init(Cipher.ENCRYPT_MODE, keyspec, ivspec);
return new String(toHexString(cipher.doFinal(padChar(text,
'\u0000', 16).getBytes())));
} catch (Exception e) {
SWGAide.printError("SimpleCrypto:encryptedAES: ", e);
}
return text;
}
need help converting java encryption to delphi
Started by Ewe Loon, Dec 12 2010 10:51 AM
3 replies to this topic
#1
Posted 12 December 2010 - 10:51 AM
I tracked the following java code down, and need to convert it to deplhi , anyone able to help
|
|
|
#2
Posted 12 December 2010 - 02:18 PM
The problem is there isn't a built in library for Delphi encryption, like there is with Java. Your first step will be to get an appropriate library (there are some free ones) and add them to your Delphi installation.
#3
Posted 12 December 2010 - 04:01 PM
I have already downloaded many encryption libs for delphi, but the problem is most of them dont use a key, but the one used by java uses 2 keys, (keyspec, ivspec)
nothing I have looked at does this.
nothing I have looked at does this.
#4
Posted 13 December 2010 - 03:42 AM
Ewe Loon said:
I have already downloaded many encryption libs for delphi, but the problem is most of them dont use a key
All encryprion uses key. You may confuse it with hashing when think of encryption without key.
To port the code you have to understand what ivspec is, i.e. why does that java code needs it. Perhaps you need to study that java Cipher library to get better understanding. Then translate or find workaround.
What is your encryption library? if you are using DCPCrypt (my favorite) then you must note that AES is the same with Rijndael.
Ewe Loon said:
, but the one used by java uses 2 keys, (keyspec, ivspec) nothing I have looked at does this.
Well, actually it's nothing special. That line was just initializing the Cipher object. This usually to make sure that same content do not encrypted into the same values. To increase the difficulty for attackers. I forgot the term for this. Salting is one popular method for this .
But like I have stated initially, you still need to know the detail of ivspec to know the exact translation or workaround to do.


Sign In
Create Account


Back to top









