I have a data block, which can be decrypted in C# with this code:
PasswordDeriveBytes pdb = new PasswordDeriveBytes(password, salt);
byte[] key = pdb.CryptDeriveKey("TripleDES", "SHA1", 192, iv);
var csp = new TripleDESCryptoServiceProvider();
csp.Mode = CipherMode.CBC;
csp.IV = iv;
csp.Key = key;
csp.Padding = PaddingMode.None;
var plainTextBytes = new byte[32*1024];
var decryptor = csp.CreateDecryptor();
int decr = decryptor.TransformBlock(cipherText, 0, cipherText.Length, plainTextBytes, 0);
My main goal to do the same in java. I'm trying to do this with this PasswordDerivedBytes port solution.
Here is my code:
PasswordDeriveBytes myPass = new PasswordDeriveBytes(password, salt);
SecretKeyFactory kf;
try {
Cipher desEDE = Cipher.getInstance("DESede/CB/NoPadding");
kf = SecretKeyFactory.getInstance("DESede");
key = myPass.getBytes(192);
desEDEKey= kf.generateSecret(new DESedeKeySpec(key));
byte[] iv = DatatypeConverter.parseBase64Binary(ivText);
desEDE.init(Cipher.DECRYPT_MODE, desEDEKey, new IvParameterSpec(iv));
byte[] ct = desEDE.doFinal(DatatypeConverter.parseBase64Binary(texts));
}
The problem is that the key created by C# CryptDerviedKey is not equal to one generated in java with getBytes(192). When this key is just copied from C# to java then all work fine, so the problem exactly in this place. Please help to port CryptDeriveKey("TripleDES", "SHA1", 192, iv) algorithm to java correctly;