Link to home
Start Free TrialLog in
Avatar of hameeds
hameeds

asked on

Triple DES encryption with MD5 hashkey

Anyone worked on this type of encryption. Please help.

The following parameters should be used as part of the encryption process.
Key Size : 164 bytes
Block Size : 128 bytes
Key : generated dynamically

I m getting the following error:
Key is suppose to be 164 bytes. but DESede key requires 24 bytes.
 Not sure where is the error. Please help

Exception in thread "main" java.security.InvalidKeyException: Wrong key size
      at javax.crypto.spec.DESedeKeySpec.<init>(DashoA12275)
      at javax.crypto.spec.DESedeKeySpec.<init>(DashoA12275)
     

(Edited by _alias99)
import org.apache.commons.codec.b
inary.*;
import java.security.spec.AlgorithmParameterSpec; 
 
public class Multiply{
private long expireTimeInMilliseconds;
 
        public static void main(String[] args) throws Exception {
               
 
                String s = integerObj + "0";
                integerObj = Integer.parseInt(s);
 
               if(args.length != 2){
                                                System.out.println("Usage: java Multiply <rows> <columns>");
                                                System.exit(0);
                                                }
                                                int rows = 0, columns = 0;
                                                try{
                                                rows = Integer.parseInt(args[0]);
                                                columns = Integer.parseInt(args[1]);
                                                }catch(NumberFormatException e){
                                                System.out.println("Wrong parameter(s)");
                                                System.exit(0);
                                                }
                                                System.out.println("Multiplication Table ("+rows+" X "+columns+")");
                                                for(int i = 1;i <= rows;i++){
                                                System.out.print(i+"\t>");
                                                for(int j = 1;j <= columns;j++)
                                                System.out.print("\t"+(i*j));
                                                System.out.println("");
        }
 
    public void setExpireTimeInDays(int expireTimeInDays)
{
   expireTimeInMilliseconds = ((long) expireTimeInDays) * 24 * 60 * 60 * 1000;
}

Open in new window

Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

>> Hash code MD5 generates how many bytes?

16. You've another question open on this still?
Avatar of hameeds
hameeds

ASKER

I think I have resolved a part of it. This is different issue.  i get  another issue with the above code.

Exception in thread "main" java.security.InvalidKeyException: Wrong key size
      at javax.crypto.spec.DESedeKeySpec.<init>(DashoA12275)
      at javax.crypto.spec.DESedeKeySpec.<init>(DashoA12275)
      at TripleDES.main(TripleDES.java:26)

Once I resolve completely, I will accept solution.
As you solve parts of the picture you should really be closing the questions as you go along or things tend to get out of hand and can lead to a lack of focus.

Anyway, you should probably be looking into what that .NET code does with the MD5 hash and doing exactly the same
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>>why are you MD5'ing the password to make a key?

Err... because the native code is doing so?

Is that the case hameeds?
Avatar of hameeds

ASKER

Thank you for your support. I  was recently in trouble for posting some  Security Aglorithm which is sensitive and proprietary information. Please REPLACE  the post code snippet with the following code snippet.

import org.apache.commons.codec.binary.*;
import java.security.spec.AlgorithmParameterSpec; 
 
public class Multiply{
private long expireTimeInMilliseconds;
 
        public static void main(String[] args) throws Exception {
               
 
                String s = integerObj + "0";
                integerObj = Integer.parseInt(s);
 
               if(args.length != 2){
								System.out.println("Usage: java Multiply <rows> <columns>");
								System.exit(0);
								}
								int rows = 0, columns = 0;
								try{
								rows = Integer.parseInt(args[0]);
								columns = Integer.parseInt(args[1]);
								}catch(NumberFormatException e){
								System.out.println("Wrong parameter(s)");
								System.exit(0);
								}
								System.out.println("Multiplication Table ("+rows+" X "+columns+")");
								for(int i = 1;i <= rows;i++){
								System.out.print(i+"\t>");
								for(int j = 1;j <= columns;j++)
								System.out.print("\t"+(i*j));
								System.out.println("");
        }
 
    public void setExpireTimeInDays(int expireTimeInDays)
{
   expireTimeInMilliseconds = ((long) expireTimeInDays) * 24 * 60 * 60 * 1000;
}

Open in new window