def get_key_and_iv(password, salt, klen=32, ilen=16, msgdgst='md5'):
    """
	Derive the key and the IV from the given password and salt.
	This is a niftier implementation than my direct transliteration of
	the C++ code although I modified to support different digests.
	CITATION: http://stackoverflow.com/questions/13907841/implement-openssl-aes-encryption-in-python
	@param password  The password to use as the seed.
	@param salt	  The salt.
	@param klen	  The key length.
	@param ilen	  The initialization vector length.
	@param msgdgst   The message digest algorithm to use.
	"""
    mdf = getattr(__import__('hashlib', fromlist=[msgdgst]), msgdgst)
    password = password.encode('ascii', 'ignore')
    try:
        maxlen = klen + ilen
        keyiv = mdf(password + salt).digest()
        tmp = [keyiv]
        while len(tmp) < maxlen:
            tmp.append(mdf(tmp[-1] + password + salt).digest())
            keyiv += tmp[-1]
        key = keyiv[:klen]
        iv = keyiv[klen:klen + ilen]
        return key, iv
    except UnicodeDecodeError:
        return None, None
