parameters: (data, passphrase)
return_statement: return unpad(pt, cipher.block_size)
docstring: Decrypt a piece of data using a passphrase and *PBES1*.
  
          The algorithm to use is automatically detected.
  
          :Parameters:
            data : byte string
              The piece of data to decrypt.
            passphrase : byte string
              The passphrase to use for decrypting the data.
          :Returns:
            The decrypted data, as a binary string.
docstring_summary: Decrypt a piece of data using a passphrase and *PBES1*.
docstring_tokens: Decrypt a piece of data using a passphrase and * PBES1 * .
function: def decrypt(data, passphrase):
          """Decrypt a piece of data using a passphrase and *PBES1*.
  
          The algorithm to use is automatically detected.
  
          :Parameters:
            data : byte string
              The piece of data to decrypt.
            passphrase : byte string
              The passphrase to use for decrypting the data.
          :Returns:
            The decrypted data, as a binary string.
          """
  
          enc_private_key_info = DerSequence().decode(data)
          encrypted_algorithm = DerSequence().decode(enc_private_key_info[0])
          encrypted_data = DerOctetString().decode(enc_private_key_info[1]).payload
  
          pbe_oid = DerObjectId().decode(encrypted_algorithm[0]).value
          cipher_params = {}
          if pbe_oid == _OID_PBE_WITH_MD5_AND_DES_CBC:
              # PBE_MD5_DES_CBC
              hashmod = MD5
              ciphermod = DES
          elif pbe_oid == _OID_PBE_WITH_MD5_AND_RC2_CBC:
              # PBE_MD5_RC2_CBC
              hashmod = MD5
              ciphermod = ARC2
              cipher_params['effective_keylen'] = 64
          elif pbe_oid == _OID_PBE_WITH_SHA1_AND_DES_CBC:
              # PBE_SHA1_DES_CBC
              hashmod = SHA1
              ciphermod = DES
          elif pbe_oid == _OID_PBE_WITH_SHA1_AND_RC2_CBC:
              # PBE_SHA1_RC2_CBC
              hashmod = SHA1
              ciphermod = ARC2
              cipher_params['effective_keylen'] = 64
          else:
              raise PbesError("Unknown OID for PBES1")
  
          pbe_params = DerSequence().decode(encrypted_algorithm[1], nr_elements=2)
          salt = DerOctetString().decode(pbe_params[0]).payload
          iterations = pbe_params[1]
  
          key_iv = PBKDF1(passphrase, salt, 16, iterations, hashmod)
          key, iv = key_iv[:8], key_iv[8:]
  
          cipher = ciphermod.new(key, ciphermod.MODE_CBC, iv, **cipher_params)
          pt = cipher.decrypt(encrypted_data)
          return unpad(pt, cipher.block_size)
function_tokens: def decrypt ( data , passphrase ) : enc_private_key_info = DerSequence ( ) . decode ( data ) encrypted_algorithm = DerSequence ( ) . decode ( enc_private_key_info [ 0 ] ) encrypted_data = DerOctetString ( ) . decode ( enc_private_key_info [ 1 ] ) . payload pbe_oid = DerObjectId ( ) . decode ( encrypted_algorithm [ 0 ] ) . value cipher_params = { } if pbe_oid == _OID_PBE_WITH_MD5_AND_DES_CBC : # PBE_MD5_DES_CBC hashmod = MD5 ciphermod = DES elif pbe_oid == _OID_PBE_WITH_MD5_AND_RC2_CBC : # PBE_MD5_RC2_CBC hashmod = MD5 ciphermod = ARC2 cipher_params [ 'effective_keylen' ] = 64 elif pbe_oid == _OID_PBE_WITH_SHA1_AND_DES_CBC : # PBE_SHA1_DES_CBC hashmod = SHA1 ciphermod = DES elif pbe_oid == _OID_PBE_WITH_SHA1_AND_RC2_CBC : # PBE_SHA1_RC2_CBC hashmod = SHA1 ciphermod = ARC2 cipher_params [ 'effective_keylen' ] = 64 else : raise PbesError ( "Unknown OID for PBES1" ) pbe_params = DerSequence ( ) . decode ( encrypted_algorithm [ 1 ] , nr_elements = 2 ) salt = DerOctetString ( ) . decode ( pbe_params [ 0 ] ) . payload iterations = pbe_params [ 1 ] key_iv = PBKDF1 ( passphrase , salt , 16 , iterations , hashmod ) key , iv = key_iv [ : 8 ] , key_iv [ 8 : ] cipher = ciphermod . new ( key , ciphermod . MODE_CBC , iv , * * cipher_params ) pt = cipher . decrypt ( encrypted_data ) return unpad ( pt , cipher . block_size )