Triple DES Perl to Java
Hi,
I am having a base64 encoded data block, which has been triple des
encrypted with Perl's Crypt::TripleDES class
(http://search.cpan.org/dist/Crypt-TripleDES/lib/Crypt/TripleDES.pm) and
am trying to decrypt it with Java.
My problem is now that whatever I already tried I always get some
exception with messages from a wrong padding to nonexistent algorithms.
Below is some sample code with "O2OsvkIsfY0=" as base64 encoded data
block (decoded "data") and "key" as encryption key.
import java.security.*;
import javax.crypto.*;
import javax.crypto.spec.*;
import sun.misc.BASE64Decoder;
public class Test
{
public static void main(String args[]) throws Exception
{
String data="O2OsvkIsfY0=";
String key="key";
// PBE parameter specification with random values for salt
// and iteration
PBEParameterSpec pbeParamSpec = new PBEParameterSpec(new
byte[]{5, 10, 20, 30, 10, 85, 86, 3}, 20);
byte b_data[]=new BASE64Decoder().decodeBuffer(data);
PBEKeySpec keyspec=new PBEKeySpec(key.toCharArray());
SecretKeyFactory
skf=SecretKeyFactory.getInstance("PBEWITHSHA1ANDDESEDE");
SecretKey sk=skf.generateSecret(keyspec);
Cipher cipher=Cipher.getInstance("PBEWITHSHA1ANDDESEDE");
cipher.init(Cipher.DECRYPT_MODE, sk, pbeParamSpec);
System.out.println(cipher.doFinal(b_data).toString());
}
}
I hope that someone can shed a bit light into this, as I am really lost.
On a related note, I noticed that SecretKeyFactory.generateSecret()
throws an InvalidKeySpecException "Password is not ASCII" exception when
the key contains a ? symbol. Does this mean the Java implementation cant
handle such characters within the key?
Thanks very much,
Alexander