I am having issue while understanding the concept between triple Des algorithm of java and python. In java the key for the encryption is 48 chars long whereas the same key cannot be applied in case of python. I tried with both the suggestions mentioned here but it doesnot seem to work with either way. I cannot decrypt the string encrypted by java in python. The code in java look like:
import java.security.spec.KeySpec;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESedeKeySpec;
public class SecretKeyEncryptionExample
{
private static final String FORMAT = "ISO-8859-1";
public static final String DESEDE_ENCRYPTION_SCHEME = "DESede";
private KeySpec ks;
private SecretKeyFactory skf;
private Cipher cipher;
SecretKey key;
public SecretKeyEncryptionExample()
throws Exception
{
String myEncryptionKey = "<48 chars long string>";
this.ks = new DESedeKeySpec(myEncryptionKey.getBytes("ISO-8859-1"));
this.skf = SecretKeyFactory.getInstance("DESede");
this.cipher = Cipher.getInstance("DESede");
this.key = this.skf.generateSecret(this.ks);
}
Whereas in python if I use:
from pyDes import *
import hashlib
import base64
key1 = "<48 chars long key>".decode('hex')
data = "<Some encrypted strings>"
k = triple_des(key1, ECB, "\0\0\0\0\0\0\0\0", pad=None, padmode=PAD_PKCS5)
e = k.decrypt(data)
print e
I did it according to the first suggestion given here but it prints nothing. again I tried the second suggestion from the same page which asked to use first 24 chars as key and ignore rest as:
from pyDes import *
import hashlib
import base64
key1 = "<taking only first 24 chars long key>"
data = "<Some encrypted data>"
k = triple_des(key1, ECB, "\0\0\0\0\0\0\0\0", pad=None, padmode=PAD_PKCS5)
e = k.decrypt(data)
print e
But this also gives me no output.. I am confused with all this research. Please suggest which way is the correct one and why I am not getting any output from either of these. Thanks..