dmak
2004-11-02 20:43:43 UTC
Hi,
I am trying to encrypt a string using MD5. Following is the piece of code.
I get the error "java.security.InvalidKeyException: Wrong key size" at the
following line
DESedeKeySpec desedeKeySpec = new DESedeKeySpec(pwdhash);
Any help is appreciated . Thank U
Code:-
public static void main (String args[]) {
arg = args[0];
try {
password = "secretpassword1!";
MessageDigest md = MessageDigest.getInstance("MD5");
pwdhash = md.digest(password.getBytes());
md = null;
DESedeKeySpec desedeKeySpec = new DESedeKeySpec(pwdhash);
System.out.println("Work");
SecretKeyFactory keyFactory =
SecretKeyFactory.getInstance("DESede");
Key desKey = (Key) keyFactory.generateSecret(desedeKeySpec);
desCipher = Cipher.getInstance("DESede/ECB/PKCS5Padding");
desCipher.init(Cipher.ENCRYPT_MODE, desKey);
}
catch(Exception e) {
System.out.println("e "+e);
}
String encr = encrypt(arg);
}
I am trying to encrypt a string using MD5. Following is the piece of code.
I get the error "java.security.InvalidKeyException: Wrong key size" at the
following line
DESedeKeySpec desedeKeySpec = new DESedeKeySpec(pwdhash);
Any help is appreciated . Thank U
Code:-
public static void main (String args[]) {
arg = args[0];
try {
password = "secretpassword1!";
MessageDigest md = MessageDigest.getInstance("MD5");
pwdhash = md.digest(password.getBytes());
md = null;
DESedeKeySpec desedeKeySpec = new DESedeKeySpec(pwdhash);
System.out.println("Work");
SecretKeyFactory keyFactory =
SecretKeyFactory.getInstance("DESede");
Key desKey = (Key) keyFactory.generateSecret(desedeKeySpec);
desCipher = Cipher.getInstance("DESede/ECB/PKCS5Padding");
desCipher.init(Cipher.ENCRYPT_MODE, desKey);
}
catch(Exception e) {
System.out.println("e "+e);
}
String encr = encrypt(arg);
}