Factory to create hash functions from configuration section. If an
    algorithm takes custom parameters, you can separate them by a colon like
    this: pbkdf2:arg1:arg2:arg3.
962416
def new(conf):
    """"""

    algorithm = conf.get("algorithm")
    salt = conf.get("salt").encode("utf-8")

    if algorithm == "none":
        return Hash(salt, None)
    elif algorithm.startswith("pbkdf2"):
        kwargs = {}
        tail = algorithm.partition(":")[2]
        for func, key in ((int, "iterations"), (int, "dklen"), (str, "func")):
            head, _, tail = tail.partition(":")
            if not head:
                break
            kwargs[key] = func(head)

        return PBKDF2(salt, **kwargs)
    else:
        return Hash(salt, algorithm)
179345
public static HashCode newHash(String input, HashFunction function) {
        return function.hashString(input, Charsets.UTF_8);
    }
856888
def _hash_internal(method, salt, password):
    
    if method == 'plain':
        return password, method

    if isinstance(password, text_type):
        password = password.encode('utf-8')

    if method.startswith('pbkdf2:'):
        args = method[7:].split(':')
        if len(args) not in (1, 2):
            raise ValueError('Invalid number of arguments for PBKDF2')
        method = args.pop(0)
        iterations = args and int(args[0] or 0) or DEFAULT_PBKDF2_ITERATIONS
        is_pbkdf2 = True
        actual_method = 'pbkdf2:%s:%d' % (method, iterations)
    else:
        is_pbkdf2 = False
        actual_method = method

    hash_func = _hash_funcs.get(method)
    if hash_func is None:
        raise TypeError('invalid method %r' % method)

    if is_pbkdf2:
        if not salt:
            raise ValueError('Salt is required for PBKDF2')
        rv = pbkdf2_hex(password, salt, iterations,
                        hashfunc=hash_func)
    elif salt:
        if isinstance(salt, text_type):
            salt = salt.encode('utf-8')
        rv = hmac.HMAC(salt, password, hash_func).hexdigest()
    else:
        h = hash_func()
        h.update(password)
        rv = h.hexdigest()
    return rv, actual_method
79980
def construct(key_data, algorithm=None):
    

    # Allow for pulling the algorithm off of the passed in jwk.
    if not algorithm and isinstance(key_data, dict):
        algorithm = key_data.get('alg', None)

    if not algorithm:
        raise JWKError('Unable to find a algorithm for key: %s' % key_data)

    key_class = get_key(algorithm)
    if not key_class:
        raise JWKError('Unable to find a algorithm for key: %s' % key_data)
    return key_class(key_data, algorithm)
273953
function mapFactory (params) {

    if (typeof params === 'function') {
        return params;
    }

    var regs = [];
    (params || []).forEach(function (params) {
        if (typeof params[0] === 'string') {
            params[0] = new RegExp(params[0]);
        }
        regs.push(params);
    });

    // @param   {String}
    // @param   {String}
    return regs.length ? function map (src) {

        if (!src) {
            return src;
        }

        regs.forEach(function (reg) {
            src = src.replace.apply(src, reg);
        });

        return src;

    } : function (src) {
        return src;
    };
}
80217
function getk(params) {
  var k_buf = crypto
    .createHash(params.hash)
    .update(padToN(params.N, params))
    .update(padToN(params.g, params))
    .digest();
  return(new BigInteger(k_buf));
}
715119
def hash_args(*args, **kwargs):
    """"""
    arg_string = '_'.join([str(arg) for arg in args])
    kwarg_string = '_'.join([str(key) + '=' + str(value)
                             for key, value in iteritems(kwargs)])
    combined = ':'.join([arg_string, kwarg_string])

    hasher = md5()
    hasher.update(b(combined))
    return hasher.hexdigest()
388236
function pwCipher(string) {

        if(string) {

            if ( typeof pw !== 'string' || pw.length < 8 ) {
                throw new Error('Please set a password with 8 or ' +
                    'more chars on process.env.CIPHER_UTIL_PW!');
            }

            if ( typeof algo !== 'string' || algo.length < 1 ) {
                throw new Error('Please choose an algorithm' +
                    ' on process.env.CIPHER_UTIL_ALGO!');
            }

            var ciphered = crypto.createCipher(algo, pw),

            /*
             * Array
             */
            encrypted = [ciphered.update(string)];

            encrypted.push(ciphered.final());

            return Buffer.concat(encrypted).toString(pwEnc);

        }

        return null;

    }
1181128
def generate_k(order, secexp, hash_func, data):
    '''
        
    '''

    qlen = bit_length(order)
    holen = hash_func().digest_size
    rolen = (qlen + 7) / 8
    bx = number_to_string(secexp, order) + bits2octets(data, order)

    # Step B
    v = b('\x01') * holen

    # Step C
    k = b('\x00') * holen

    # Step D

    k = hmac.new(k, v+b('\x00')+bx, hash_func).digest()

    # Step E
    v = hmac.new(k, v, hash_func).digest()

    # Step F
    k = hmac.new(k, v+b('\x01')+bx, hash_func).digest()

    # Step G
    v = hmac.new(k, v, hash_func).digest()

    # Step H
    while True:
        # Step H1
        t = b('')

        # Step H2
        while len(t) < rolen:
            v = hmac.new(k, v, hash_func).digest()
            t += v

        # Step H3
        secret = bits2int(t, qlen)

        if secret >= 1 and secret < order:
            return secret

        k = hmac.new(k, v+b('\x00'), hash_func).digest()
        v = hmac.new(k, v, hash_func).digest()
31856
def custom_conf(self, conf):
        ''''''
        if conf:
            for (key, val) in conf.items():
                self.__conf[key] = val
        return self
481269
public static SecretKey buildKey(AbstractCipher.Algorithms algorithm, byte[] keySpec) {
        SecretKeySpec key = new SecretKeySpec(keySpec, algorithm.name());
        return key;
    }
161006
def make_signature(params, hmac_key):
    
    # produce a list of "key=value" for all entries in params except `h'
    pairs = [x + "=" + ''.join(params[x]) for x in sorted(params.keys()) if x != "h"]
    sha = hmac.new(hmac_key, '&'.join(pairs), hashlib.sha1)
    return base64.b64encode(sha.digest())
604719
def hash(self, *args, **kwargs):
        
        joiner = kwargs.get('joiner', '').encode('utf-8')
        as_bytes = kwargs.get('as_bytes', False)

        def conv(arg):
            if isinstance(arg, integer_types):
                arg = int_to_bytes(arg)

            if PY3:
                if isinstance(arg, str):
                    arg = arg.encode('utf-8')
                return arg

            return str(arg)

        digest = joiner.join(map(conv, args))

        hash_obj = self._hash_func(digest)

        if as_bytes:
            return hash_obj.digest()

        return int_from_hex(hash_obj.hexdigest())
755705
def get_function_hash(self, func, args=None, kwargs=None, ttl=None, key=None, noc=None):
        

        base_hash = settings.HASH_FUNCTION()

        if PY3:
            base_hash.update(func.__name__.encode(settings.DEFAULT_ENCODING))
        else:
            base_hash.update(func.__name__)

        if args:
            for a in args:
                if PY3:
                    base_hash.update(repr(a).encode(settings.DEFAULT_ENCODING))
                else:
                    base_hash.update(repr(a))

        if kwargs:
            for k in sorted(kwargs):
                if PY3:
                    base_hash.update(("{}={}".format(k, repr(kwargs[k]))).encode(settings.DEFAULT_ENCODING))
                else:
                    base_hash.update(("{}={}".format(k, repr(kwargs[k]))))

        if ttl:
            base_hash.update(str(ttl).encode(settings.DEFAULT_ENCODING))

        if key and can_encrypt:
            if PY3:
                base_hash.update(key.encode(settings.DEFAULT_ENCODING))
            else:
                base_hash.update(key)

        if noc:
            base_hash.update(str(noc).encode(settings.DEFAULT_ENCODING))

        base_hash_hex = base_hash.hexdigest()

        return base_hash_hex
628153
private byte[] pbkdf2(char[] password, byte[] salt) {
        try {
            PBEKeySpec spec = new PBEKeySpec(password, salt, PBKDF2_ITERATIONS, HASH_BYTE_SIZE * 8);
            SecretKeyFactory skf = SecretKeyFactory.getInstance(PBKDF2_ALGORITHM);
            return skf.generateSecret(spec).getEncoded();
        } catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
            throw SeedException.wrap(e, CryptoErrorCode.UNEXPECTED_EXCEPTION);
        }
    }
1154648
def createSign(pParams, method, host_url, request_path, secret_key):
    
    sorted_params = sorted(pParams.items(), key=lambda d: d[0], reverse=False)
    encode_params = urllib.parse.urlencode(sorted_params)
    payload = [method, host_url, request_path, encode_params]
    payload = '\n'.join(payload)
    payload = payload.encode(encoding='UTF8')
    secret_key = secret_key.encode(encoding='UTF8')

    digest = hmac.new(secret_key, payload, digestmod=hashlib.sha256).digest()
    signature = base64.b64encode(digest)
    signature = signature.decode()
    return signature
322825
def _prepare_key(key, *args, **kwargs):
    

    if not args and not kwargs:
        return key

    items = sorted(kwargs.items())
    hashable_args = (args, tuple(items))
    args_key = hashlib.md5(pickle.dumps(hashable_args)).hexdigest()

    return "%s/args:%s" % (key, args_key)