Return cryptographic hash (defaulting to: "sha1") of a string.

@param {String} str
@param {String} algo - Algorithm used for hashing, defaults to sha1
@param {String} encoding - defaults to hex
@return {String}
488932
function hash(str, algo, encoding) {
  return crypto
    .createHash(algo || 'sha1')
    .update(str)
    .digest(encoding || 'hex');
}
458962
def sha1_digest(instr):
    '''
    
    '''
    if six.PY3:
        b = salt.utils.stringutils.to_bytes(instr)
        return hashlib.sha1(b).hexdigest()
    return hashlib.sha1(instr).hexdigest()
339159
function hash(s) {
    var h = hash.BASE

    for (var i = 0, l = s.length; i < l; i++) {
        h ^= s.charCodeAt(i)
        h += (h << 1) + (h << 4) + (h << 7) + (h << 8) + (h << 24)
    }

    return h >>> 0
}
82521
function fastHash(str) {
  let hash = 5381;
  for (let j = str.length - 1; j >= 0; j -= 1) {
    hash = (hash * 33) ^ str.charCodeAt(j);
  }
  return hash >>> 0;
}
886477
public String getHash(Algorithms alg) {
        String key = normalizeKey(alg);
        if (hashes.containsKey(key)) {
            Record record = hashes.get(key);
            if (record.containsKey(FieldName.COMBINED_HASH)) {
                return (String) record.get(FieldName.COMBINED_HASH);
            }
        }
        return "";
    }
654837
public function encryptString($algo, $string, $key = null)
    {     
        if (!empty($algo) && !empty($string)) {   
            if ($key == null) {
                $ctx = hash_init($algo);
            } else {
                $ctx = hash_init($algo, HASH_HMAC, $key);
                hash_update($ctx, $string);
            }
            return hash_final($ctx);
        }
        return false;
    }
671779
function md5Hash(val) {
        if (!val) { return val; }

        var str = _.isObject(val) ? JSON.stringify(val) : val;
        var md5 = crypto.createHash('md5');
        md5.update(str);
        return md5.digest('hex');
    }
1333633
static function _hash_hmac($algo, $data, $key, $raw_output=false)
    {
        $algo = strtolower($algo);
        $pack = 'H'.strlen($algo('test'));
        $size = 64;
        $opad = str_repeat(chr(0x5C), $size);
        $ipad = str_repeat(chr(0x36), $size);

        if (strlen($key) > $size) {
            $key = str_pad(pack($pack, $algo($key)), $size, chr(0x00));
        } else {
            $key = str_pad($key, $size, chr(0x00));
        }

        $keyLastPos = strlen($key) - 1;
        for ($i = 0; $i < $keyLastPos; $i++) {
            $opad[$i] = $opad[$i] ^ $key[$i];
            $ipad[$i] = $ipad[$i] ^ $key[$i];
        }

        $output = $algo($opad.pack($pack, $algo($ipad.$data)));

        return ($raw_output) ? pack($pack, $output) : $output;
    }
1309619
public static String createAlphanumericHash(final String str, final int length) {
		try {
			final MessageDigest md = MessageDigest.getInstance("SHA-256");
			final byte[] digest = md.digest(str.getBytes(CHARSET_UTF8));
			// To human
			final StringBuilder sb = new StringBuilder();
			for (final byte b : digest) {
				if (b < 16) sb.append("0");
				sb.append(Integer.toHexString(b & 0xff));
			}
			// repeat if to small
			while (sb.length() < length) {
				sb.append(sb.toString());
			}
			// truncation and return
			return sb.delete(length, sb.length()).toString();
		} catch (NoSuchAlgorithmException | UnsupportedCharsetException e) {
			// Hashalgo. and charset is mandatory for all kinds of JDK, so this should happend. But even when, we generate a random string.
			return createRandomAlphanumeric(length);
		}
	}
991591
public function hash($string, $algo)
    {
        if (true === empty($string)) {
            $string = microtime() . uniqid();
        }

        return hash($algo, $string);
    }
39286
function encrypt (str) {
    var cipher = crypto.createCipher(algorithm, key)
      , crypted = cipher.update(str, from, to) + cipher.final(to)
    return crypted;
  }
233439
public function getHash($algo = 'sha1', $raw = false)
    {
        $result = false;

        if ($this->isReadable() && $this->isSeekable())
        {
            $current = $this->peek();
            if ($this->seek(0) && in_array($algo, hash_algos()))
            {
                $hash = hash_init($algo);
                hash_update_stream($hash, $this->_resource);
                $result = hash_final($hash, (bool) $raw);
                $this->seek($current);
            }
        }

        return $result;
    }
699325
private String sha512hash(String str) {
        return Hashing.sha512().hashBytes(str.getBytes(getEncoding())).toString();
    }
1098262
function computeHash(filename, algo, callback) {
    var crypto = require('crypto');
    var fs = require('fs');

    var chksum = crypto.createHash(algo);

    var s = fs.ReadStream(filename);
    s.on('error', function (err) {
        //no file, hash will be zero
        callback(0, err);
    });
    s.on('data', function (d) {
        chksum.update(d);
    });

    s.on('end', function () {
        var d = chksum.digest('hex');
        //util.debug(d + '  ' + filename);
        callback(d);
    });
}
653673
public function hash($algo = 'md5', $format = null, $raw_output = false)
	{
		return hash($algo, parent::format($format === null ? static::$format : $format), $raw_output);
	}
440822
public static String
algString(int alg) throws UnsupportedAlgorithmException {
	switch (alg) {
	case Algorithm.RSAMD5:
		return "MD5withRSA";
	case Algorithm.DSA:
	case Algorithm.DSA_NSEC3_SHA1:
		return "SHA1withDSA";
	case Algorithm.RSASHA1:
	case Algorithm.RSA_NSEC3_SHA1:
		return "SHA1withRSA";
	case Algorithm.RSASHA256:
		return "SHA256withRSA";
	case Algorithm.RSASHA512:
		return "SHA512withRSA";
	default:
		throw new UnsupportedAlgorithmException(alg);
	}
}
1263077
public static byte[] sha256Bytes(String str) {
        if (str == null) return null;
        MessageDigest digester;
        try {
            digester = MessageDigest.getInstance("SHA-256");
        } catch (NoSuchAlgorithmException ex) {
            throw new RuntimeException(ex);
        }
        return digester.digest(str.getBytes());
    }