Generates a hash from a given String
    with a specified algorithm and returns the
    hash in hexadecimal form. Default: sha256.
172481
def hash_input(inpt, algo=HASH_SHA256):
    """"""
    if (algo == HASH_MD5):
        hashcode = hashlib.md5()
    elif (algo == HASH_SHA1):
        hashcode = hashlib.sha1()
    elif (algo == HASH_SHA224):
        hashcode = hashlib.sha224()
    elif (algo == HASH_SHA256):
        hashcode = hashlib.sha256()
    elif (algo == HASH_SHA384):
        hashcode = hashlib.sha384()
    elif (algo == HASH_SHA512):
        hashcode = hashlib.sha512()

    if sys.version_info.major == 2:
        inpt = bytes(inpt)
    else:
        inpt = bytes(inpt, "utf-8")

    hashcode.update(inpt)
    hexhash = hashcode.hexdigest()
    return hexhash
243960
function (str, algorithm, encoding) {
        try {
            return crypto
                .createHash(algorithm || 'md5')
                .update(str, 'utf8')
                .digest(encoding || 'hex')
        } catch (err) {
            return err
        }
    }
176341
function checksum(src, algorithm='sha256', outputFormat='hex'){
    return new Promise(async function(resolve, reject){
        // hash engine
        const hash = _crypto.createHash(algorithm);

        // events
        hash.on('readable', function(){
            // get hashsum
            const sum = hash.read();

            // data available ?
            if (!sum){
                return;
            }

            // hex, base64 or buffer
            switch (outputFormat){
                case 'base64':
                    resolve(sum.toString('base64'));
                    break;
                case 'raw':
                case 'buffer':
                    resolve(sum);
                    break;
                default:
                    resolve(sum.toString('hex'));
                    break;
            }
        });
        hash.on('error', function(e){
            reject(e);
        })

        try{
            // open file input stream
            const input = await _fInputStream(src);

             // stream hashing
            input.pipe(hash);
        }catch(e){
            reject(e);
        }
    });
}
398353
def make_hash(s, n_bytes):
    """"""
    raw_h = int(md5(s.encode('utf-8')).hexdigest()[:n_bytes], 16)
    # Make it a signed int.
    return 16**n_bytes//2 - raw_h
42492
public static String getHashSHA256(String text) {
        byte[] bytes = text.getBytes(StandardCharsets.ISO_8859_1);
        return getHashSHA256(bytes);
    }
809795
public static String sha256Hex(String data, String charset) {
		return new Digester(DigestAlgorithm.SHA256).digestHex(data, charset);
	}
617103
public static String sha256(String string) throws NoSuchAlgorithmException, UnsupportedEncodingException {
        MessageDigest messageDigest;
        messageDigest = MessageDigest.getInstance("SHA-256");
        byte[] hash = messageDigest.digest(string.getBytes("UTF-8"));
        return String.valueOf(Hex.encodeHex(hash));
    }
612059
function P_hash(secret, seed, outputLength, algorithm) {
    let result = Buffer.alloc(0); // empty buffer
    let hmac;

    // for the initial iteration, set the (initial) data to our seed
    let data = seed;
    while (result.length < outputLength) {
        // calculate the hmac for our current 'data' value (our seed on the initiatial iteration...or an iterative hmac of that seed in later iterations)
        hmac = exports.crypto.createHmac(algorithm, secret).update(data).digest();
        // save this hmac result as the 'data' input for the next iteration
        let dataForNextIteration = hmac;
        // concatenate the hmac and our seed
        data = Buffer.concat([hmac, seed]);
        // calculate an hmac for the hmac-plus-seed (which we will store in our output)
        hmac = exports.crypto.createHmac(algorithm, secret).update(data).digest();
        // add the hmac to our result
        result = Buffer.concat([result, hmac]);
        // restore the saved first-interation-stage hmac as the 'data' input for our next iteration
        data = dataForNextIteration;
    }

    // if our HMAC's output block size resulted in a length which is slightly too big, discard the extra bytes.
    if (result.length > outputLength) {
        let truncatedBuffer = Buffer.alloc(outputLength);
        result.copy(truncatedBuffer, 0, 0, outputLength);
        result = truncatedBuffer;
    }

    // return the hash result (with the number of octects/bytes specified as 'outputLength' by the caller)
    return result;
}
646531
def generate_hash(self):
        
        from django.utils.hashcompat import sha_constructor
        hash = sha_constructor(settings.SECRET_KEY + self.url + self.email + unicode(datetime.now()) ).hexdigest()
        return hash[::2]
38937
def hash(mapping, bind, values):
    
    for v in values:
        if v is None:
            continue
        if not isinstance(v, six.string_types):
            v = six.text_type(v)
        yield sha1(v.encode('utf-8')).hexdigest()
586935
def gen_hash(crypt_salt=None, password=None, algorithm='sha512'):
    '''
    
    '''
    if not HAS_CRYPT:
        raise SaltInvocationError('No crypt module for windows')

    hash_algorithms = dict(
        md5='$1$', blowfish='$2a$', sha256='$5$', sha512='$6$'
    )
    if algorithm not in hash_algorithms:
        raise SaltInvocationError(
            'Algorithm \'{0}\' is not supported'.format(algorithm)
        )

    if password is None:
        password = secure_password()

    if crypt_salt is None:
        crypt_salt = secure_password(8)

    crypt_salt = hash_algorithms[algorithm] + crypt_salt

    return crypt.crypt(password, crypt_salt)
1139354
public static String hashSHA256asStringHex(String input) throws NoSuchAlgorithmException {
		byte[] output = hashSHA256(input.getBytes());
		StringBuilder sb = new StringBuilder("0x");
		 for (byte b : output) {
		    sb.append(hexDigit[(b >> 4) & 0x0f]);
		    sb.append(hexDigit[b & 0x0f]);
		 }
		 return sb.toString();
	}
83101
function hmac(text, format) {
    format = format || 'hex';
    return crypto.createHmac('sha256', cryptoKey).update(text).digest(format);
  }
701922
def genkeyhex():
    '''
    
    '''

    while True:
        key = hash256(
                hexlify(os.urandom(40) + str(datetime.datetime.now())
                                            .encode("utf-8")))
        # 40 bytes used instead of 32, as a buffer for any slight
        #     lack of entropy in urandom
        # Double-sha256 used instead of single hash, for entropy
        #     reasons as well.
        # I know, it's nit-picking, but better safe than sorry.

        if int(key,16) > 1 and int(key,16) < N:
            break
    return key
1016643
public static String generateShaHash(String text) {
		try {
			MessageDigest digest = MessageDigest.getInstance(SHA_ALGORITHM);
			byte[] bytes = text.getBytes(UTF_8);
			bytes = digest.digest(bytes);
			return toHexEncode(bytes);
		} catch (Exception e) {
			throw new UnexpectedException(e);
		}
	}
381518
def hash(file):
    

    exists(file)
    log(_("hashing {}...").format(file))

    # https://stackoverflow.com/a/22058673
    with open(file, "rb") as f:
        sha256 = hashlib.sha256()
        for block in iter(lambda: f.read(65536), b""):
            sha256.update(block)
        return sha256.hexdigest()
835788
def uuid_from_string(string)
      hash = Digest::SHA1.new
      hash.update(string)
      ary = hash.digest.unpack('NnnnnN')
      ary[2] = (ary[2] & 0x0FFF) | (5 << 12)
      ary[3] = (ary[3] & 0x3FFF) | 0x8000
      # rubocop:disable Style/FormatString
      '%08x-%04x-%04x-%04x-%04x%08x' % ary
    end