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);
}
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 546 |
Nodes: | 16 (2 / 14) |
Uptime: | 00:19:41 |
Calls: | 10,385 |
Calls today: | 2 |
Files: | 14,057 |
Messages: | 6,416,567 |