def derive_key(secret, salt, iterations=1000, keylen=32):
 assert (type(secret) in [six.text_type, six.binary_type])
 assert (type(salt) in [six.text_type, six.binary_type])
 assert (type(iterations) in six.integer_types)
 assert (type(keylen) in six.integer_types)
 if (type(secret) == six.text_type):
  secret = secret.encode('utf8')
 if (type(salt) == six.text_type):
  salt = salt.encode('utf8')
 key = pbkdf2(secret, salt, iterations, keylen)
 return binascii.b2a_base64(key).strip()

def derive_key ( secret , salt , iterations = 1000 , keylen = 32 ) : assert ( type ( secret ) in [ six . text_type , six . binary_type ] ) assert ( type ( salt ) in [ six . text_type , six . binary_type ] ) assert ( type ( iterations ) in six . integer_types ) assert ( type ( keylen ) in six . integer_types ) if ( type ( secret ) == six . text_type ) : secret = secret . encode ( 'utf8' ) if ( type ( salt ) == six . text_type ) : salt = salt . encode ( 'utf8' ) key = pbkdf2 ( secret , salt , iterations , keylen ) return binascii . b2a_base64 ( key ) . strip ( )
computes a derived cryptographic key from a password according to pbkdf2 .