0

I am trying to write a java program for the following python code. Please see followings code for both the programs. My problem is both of these programs are producing different output for same encryption key and same input value. Please help me what I have done wrong?

11
  • welcome to stackoverflow. In Python you generate the iv as output of pbkdf2, in java you set iv=salt. Just a quick shot as I'm on my phone Commented Jul 18, 2020 at 15:37
  • Hey thanks Michael for the welcome. I am just a newbie to the world of python/java. I don't know how to extract IV from generated 'secretKeyfinal' in the above java program as it is done in the python program 'aes_iv = generator.read(16)' . Can you tell me how to get IV to pass in cipher.init() function. Commented Jul 18, 2020 at 17:43
  • Actually I want to write the java program producing same output as the above python program where I have predefined encryption key = '58xZ4dP3K762WtpDVt5EjqnNdfTZD844s8CAW5gGy9w7WMhuVtUPJ7xU2EMCrFQk' and salt = {83, 71, 26, 58, 54, 35, 22, 11, 83, 71, 26, 58, 54, 35, 22, 11}; Commented Jul 18, 2020 at 18:02
  • it seems your switched some data. key is the encrypted Data and mkj... is the input for pbkdf2. As I'm Not python specialist I cannot find the Java code, sorry. Just for others -what is the expected decrypted text? Commented Jul 18, 2020 at 19:11
  • 1
    I find the following differences / bugs in the Java code: 1. Don't Base64 decode the password (secretKey), 2. don't generate the IV from the salt, but via PBKDF2 (see 1. comment of Michael Fehr), 3. extend the keysize generated by PBKDF2 (128 + 256, instead of 256), 4. separate IV and key (in this order) from the byte array (originalKey.getEncoded()) generated by PBKDF2 and use both for initializing cipher. BTW, default iteration count (1000) and digest (SHA1) in the Python code match the parameters used in the Java code. Commented Jul 19, 2020 at 7:45

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.