我的任务是用运行 PHP 的系统替换旧的 Java 系统。
我在用 PHP 代码替换 java 加密方面遇到了一些困难。
cipherAlgorythm = "PBEWithMD5AndDES";
cipherTransformation = "PBEWithMD5AndDES/CBC/PKCS5Padding";
PBEParameterSpec ps = new javax.crypto.spec.PBEParameterSpec(salt, iterations);
SecretKeyFactory kf = SecretKeyFactory.getInstance(cipherAlgorythm);
SecretKey key = kf.generateSecret(new javax.crypto.spec.PBEKeySpec(password.toCharArray()));
Cipher encryptCipher = Cipher.getInstance(cipherTransformation);
encryptCipher.init(Cipher.ENCRYPT_MODE, key, ps);
byte[] output = encryptCipher.doFinal("This is a test string".getBytes("UTF-8"));
看来是Java的胆子
在 PHP 中我正在做
$hashed_key = pbkdf2('md5', $this->key, $this->salt, $this->reps , <GUESS 1>, TRUE);
$output = mcrypt_encrypt(MCRYPT_DES, $hashed_key, "This is a test string", MCRYPT_MODE_CBC, <GUESS 2>);
pbkdf2 来自here. https://defuse.ca/php-pbkdf2.htm
So <GUESS 1>
是密钥大小并且<GUESS 2>
是IV。我已经尝试过这些但无济于事。有人对这样的价值观有建议吗?据我所知,加密本身应该是可移植的,但我不确定某些 Java 方法中发生了什么。
看起来java正在某处创建IV,但我不明白如何或在哪里。
RELATED
解密(使用 PHP)Java 加密(PBEWithMD5AndDES) https://stackoverflow.com/questions/10300185/decrypt-with-php-a-java-encryption-pbewithmd5anddes