我的任务是用运行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 ,, TRUE); $output = mcrypt_encrypt(MCRYPT_DES, $hashed_key, "This is a test string", MCRYPT_MODE_CBC, );
pbkdf2来自这里.
所以
是关键的大小和
是IV.我玩这些无济于事.有没有人对这些价值观有所建议?据我所知,加密本身应该是可移植的,但我不确定某些Java方法发生了什么.
看起来java正在某处创建一个IV,但我不明白如何或在哪里.
有关
解密(使用PHP)Java加密(PBEWithMD5AndDES)