def decrypt(self, data):
        """Decrypt the data using AES-CBC algorithm

        The salt is automatically detected by looking for the SALTED_PREFIX
        at the beginning of the string.
        """
        if self.__is_salted(data):
            (key, iv) = self.__openssl_key(self.__decrypted_key,
                                           data[len(self.SALTED_PREFIX):16])
            data = data[16:]
        else:
            iv = self.ZERO_IV
            h = hashlib.md5()
            h.update(self.__decrypted_key)
            key = h.digest()

        # Todo add exception raise
        cipher = AES.new(key, AES.MODE_CBC, iv)
        decrypted_data = cipher.decrypt(data)
        return remove_padding(decrypted_data, AES.block_size)
    def decrypt(self, data):
        """Decrypt the data using AES-CBC algorithm

        The salt is automatically detected by looking for the SALTED_PREFIX
        at the beginning of the string.
        """
        if self.__is_salted(data):
            (key, iv) = self.__openssl_key(
                self.__decrypted_key, data[len(self.SALTED_PREFIX):16])
            data = data[16:]
        else:
            iv = self.ZERO_IV
            h = hashlib.md5()
            h.update(self.__decrypted_key)
            key = h.digest()

        # Todo add exception raise
        cipher = AES.new(key, AES.MODE_CBC, iv)
        decrypted_data = cipher.decrypt(data)
        return remove_padding(decrypted_data, AES.block_size)
    def decrypt_key(self, password):
        """Decript the key using password

        The password is first derived using the PBKF2 algorithm then
        it decrypted using the AES-CBC algorithm
        """
        pbkdf2 = PBKDF2(password, self.salt, self.ITERATIONS)
        derived_key = pbkdf2.read(32)
        key = derived_key[:16]
        iv = derived_key[16:]
        cipher = AES.new(key, AES.MODE_CBC, iv)
        try:
            self.__decrypted_key = remove_padding(cipher.decrypt(self.data),
                                                  AES.block_size)
        except PaddingProtocolError:
            raise DecryptionFailure, 'decryption failed for key %s' % \
                self.identifier
        self.__update_size(len(self.__decrypted_key) / 8)

        if not self.__validate_decripted_key():
            raise DecryptionFailure, 'decryption failed for key %s' % \
                self.identifier
    def decrypt_key(self, password):
        """Decript the key using password

        The password is first derived using the PBKF2 algorithm then
        it decrypted using the AES-CBC algorithm
        """
        pbkdf2 = PBKDF2(password, self.salt, self.ITERATIONS)
        derived_key = pbkdf2.read(32)
        key = derived_key[:16]
        iv = derived_key[16:]
        cipher = AES.new(key, AES.MODE_CBC, iv)
        try:
            self.__decrypted_key = remove_padding(cipher.decrypt(self.data),
                AES.block_size)
        except PaddingProtocolError:
            raise DecryptionFailure, 'decryption failed for key %s' % \
                self.identifier
        self.__update_size(len(self.__decrypted_key) / 8)
        
        if not self.__validate_decripted_key():
            raise DecryptionFailure, 'decryption failed for key %s' % \
                self.identifier