Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

need help converting java encryption to delphi

encryption

  • Please log in to reply
3 replies to this topic

#1 Ewe Loon

Ewe Loon

    CC Resident

  • Advanced Member
  • PipPipPipPip
  • 53 posts

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


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;
    }

  • 0

#2 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others

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.
  • 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/


#3 Ewe Loon

Ewe Loon

    CC Resident

  • Advanced Member
  • PipPipPipPip
  • 53 posts

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.
  • 0

#4 Luthfi

Luthfi

    CC Leader

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1320 posts
  • Programming Language:PHP, Delphi/Object Pascal, Pascal, Transact-SQL
  • Learning:C, Java, PHP

Posted 13 December 2010 - 03:42 AM

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.

, 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.
  • 0





Also tagged with one or more of these keywords: encryption

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download