#NEWLINE# def _sun_jce_pbe_decrypt( data , password , salt , iteration_count ) : #NEWLINE# #INDENT# "\n    Decrypts Sun's custom PBEWithMD5AndTripleDES password-based encryption scheme.\n    It is based on password-based encryption as defined by the PKCS #5 standard, except that it uses triple DES instead of DES.\n    Here's how this algorithm works:\n      1. Create random salt and split it in two halves. If the two halves are identical, invert one of them.\n      2. Concatenate password with each of the halves.\n      3. Digest each concatenation with c iterations, where c is the iterationCount. Concatenate the output from each digest round with the password,\n         and use the result as the input to the next digest operation. The digest algorithm is MD5.\n      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\n         form the triple DES key, and the last 8 bytes of the 2nd digest form the IV.\n    See http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b27/com/sun/crypto/provider/PBECipherCore.java#PBECipherCore.deriveCipherKey%28java.security.Key%29\n    " #NEWLINE# ( key , iv ) = _sun_jce_pbe_derive_key_and_iv ( password , salt , iteration_count ) #NEWLINE# from Crypto.Cipher import DES3 #NEWLINE# des3 = DES3 . new ( key , DES3 . MODE_CBC , IV = iv ) #NEWLINE# padded = des3 . decrypt ( data ) #NEWLINE# result = _strip_pkcs5_padding ( result ) #NEWLINE# return result