Results 1 to 1 of 1
  1. #1
    Neo Angelus is offline Member
    Join Date
    Jun 2010
    Posts
    1
    Rep Power
    0

    Default Java Blowfish port from Python(Encryption)

    Greetings everyone,

    I have a question concerning encryption and porting code from Python.

    I wanted to port the following code from Python:
    Java Code:
    from Crypto.Cipher import Blowfish
    from Crypto.Hash import MD5
    Java Code:
      md5_key = MD5.new(cleartext).digest()
    
      payload = (md5_key + cleartext)
      
      secret_key = "XXXXX_XXXXXX_XXXXXX+" + password
    
      return Blowfish.new(secret_key, 1).encrypt(payload)
    And tried it with this code:
    Java Code:
    		
    		byte[] secret_key = ("XXXXX_XXXXXX_XXXXXX+" + password).getBytes();
    
    		SecretKey secretkey = new SecretKeySpec(secret_key, "Blowfish");
    
    		Cipher cipher = Cipher.getInstance("Blowfish");
    
    		cipher.init(Cipher.ENCRYPT_MODE, secretkey);
    
    		cipher.update(md5(inputText));
    
    		return cipher.doFinal(inputText.getBytes());
    Java Code:
    	public static String md5(String to) throws Exception{
    	    MessageDigest m = MessageDigest.getInstance("MD5");
    	    m.update(to.getBytes(),0,to.length());
    	    
    	    return m.digest();
    	}
    But I ran into the following two problems:
    Fixed: The md5 payload doesn't match.(I outputted both payloads and compared them.)
    Using blowfish I get: Illegal key size or default parameters

    To be honest I'm completely lost. I've tried to fix it all afternoon, but I couldn't fix them.

    Could someone please help me?

    btw,
    The password variable is 7 characters long.
    Last edited by Neo Angelus; 06-08-2010 at 07:12 PM. Reason: Fixed md5

Similar Threads

  1. Blowfish encryption
    By Gustavo in forum Advanced Java
    Replies: 0
    Last Post: 04-14-2010, 09:38 PM
  2. Jython : python for java
    By cotarelo in forum New To Java
    Replies: 1
    Last Post: 03-25-2010, 08:53 AM
  3. Call java Methods from Python Script
    By hofsoc in forum New To Java
    Replies: 1
    Last Post: 02-18-2009, 04:47 PM
  4. Calling Java methods form Python
    By mew in forum Advanced Java
    Replies: 1
    Last Post: 12-21-2007, 02:30 PM
  5. Encryption in java
    By Ed in forum Advanced Java
    Replies: 1
    Last Post: 07-09-2007, 01:47 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •