What is the algorithm for JCEKS PBE used to encrypt the private key?

I want to decrypt the private key in Keystore Java JCEKS, and I do not want to use Java.

I can find a description of PBEWithMD5AndTripleDES, but not the actual implementation.

This comment supposedly explains the conclusion:

/** * This class implements a proprietary password-based encryption algorithm. * It is based on password-based encryption as defined by the PKCS #5 * standard, except that is uses triple DES instead of DES. * * Here how this algorithm works: * * 1. Create random salt and split it in two halves. If the two halves are * identical, invert one of them. * 2. Concatenate password with each of the halves. * 3. Digest each concatenation with c iterations, where c is the * iterationCount. Concatenate the output from each digest round with the * password, and use the result as the input to the next digest operation. * The digest algorithm is MD5. * 4. After c iterations, use the 2 resulting digests as follows: * The 16 bytes of the first digest and the 1st 8 bytes of the 2nd digest * form the triple DES key, and the last 8 bytes of the 2nd digest form the * IV. * * @author Jan Luehe * @see javax.crypto.Cipher */ 

But is this the first concatenation of password + half-of-salt , or is it half-of-salt + password ? Is the input of the next rounds password + digest , or is it digest + password .

Between 8-bit characters or full 16-bit characters and possible combinations of concatenation, you might think that as a result of trial and error I should have worked it out by now.

I know salt, iterations, and password, and even plaintext, which should decrypt the encrypted text (i.e. I have decrypted data).

Obtaining a 24-byte DES3 key, whether it is parity correction or leaving it alone, and an 8-byte IV decryption in DESC CBC mode, I cannot recreate my plaintext.

What is the algorithm described by this comment?

0
source share
1 answer

Thanks to erikson 1, who responded to a comment on this answer to another question, as well as to Ebbe M. Pedersen. In the end, I had to overturn the answer, trying to use different combinations, but somehow missed it.

For those who are interested, after you open JKS and find the entry, the encrypted PKCS # 8 shows the JCEKS 1.3.6.1.4.1.42.2.19.1 algorithm along with the salt count and iteration parameters and those with your 8-bit / char , you can decrypt the ciphertext to find the internal, unencrypted PKCS # 8 containing your private key.

 def jce_pbkdf1(password, salt, iterations) salts = [copy = salt.dup, copy.slice!((copy.length / 2)..-1)] octets = salts.map { |half| (iterations).times.inject(half) { |digest| OpenSSL::Digest.digest('md5', digest + password) } }.join return octets[0..23], octets[24..-1] // key (parity not set) and IV end 
+1
source

Source: https://habr.com/ru/post/915770/


All Articles