我在理解java和python的三重Des算法的概念时遇到了问题。在java中,加密的密钥长度为48个字符,而python则不能使用相同的密钥。我尝试了上面提到的两个建议,但似乎两种方法都不起作用。我无法在python中解密java加密的字符串。java中的代码如下所示: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);
}
而在python中,如果我使用:
^{pr2}$
我按照给出的第一个建议做了这件事,但它没有打印任何内容。我再次尝试了同一页中的第二个建议,即使用前24个字符作为键,忽略其余字符,如下所示:from pyDes import *
import hashlib
import base64
key1 = ""
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
但这也没有给我任何输出。。我对所有这些研究都感到困惑。请说明哪种方式是正确的,以及为什么我没有从这两种方法中得到任何输出。谢谢。。在