def hash_string(string_to_hash):
    """
    Hashes string using SHA-512

    :param string_to_hash: string to hash
    :type string_to_hash: str
    :return: hashed string
    """
    import crypt
    if hasattr(crypt, 'mksalt'):
        return crypt.crypt(string_to_hash, crypt.mksalt(crypt.METHOD_SHA512))
    else:
        import string
        import random
        rand = random.SystemRandom()
        salt = ''.join([rand.choice(string.ascii_letters + string.digits) for
            _ in range(8)])
        return crypt.crypt(string_to_hash, '$6$rounds={rounds}${salt}'.
            format(rounds=4096, salt=salt))
