Questions tagged [hashlib]

Hashlib is a Python module that implements a common interface to many different secure hash and message digest algorithms.

361 questions
5
votes
1 answer

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe3 in position 1: invalid continuation byte

I want to convert a byte variable to string. Of course, there are previous questions related to mine. However, trying to hash in md5() the content of a file this way: import hashlib with open("C:\\boot.ini","r") as f: …
user3522371
5
votes
1 answer

Is there a faster way (than this) to calculate the hash of a file (using hashlib) in Python?

My current approach is this: def get_hash(path=PATH, hash_type='md5'): func = getattr(hashlib, hash_type)() with open(path, 'rb') as f: for block in iter(lambda: f.read(1024*func.block_size, b''): func.update(block) …
Deneb
  • 581
  • 2
  • 6
  • 17
5
votes
1 answer

Hashlib: optimal size of chunks to be used in md5.update()

This is in reference to Get MD5 hash of big files in Python and Hashlib in Windows and Linux In responses to both these questions, it is advised to use larger chunks of data in the function md5.update() to improve performance. All testing I have…
Verma
  • 892
  • 6
  • 20
5
votes
1 answer

Hash function that protects against collisions, not attacks. (Produces a random UUID-size result space)

Using SHA1 to hash down larger size strings so that they can be used as a keys in a database. Trying to produce a UUID-size string from the original string that is random enough and big enough to protect against collisions, but much smaller than the…
Chris Dutrow
  • 42,732
  • 59
  • 174
  • 243
4
votes
2 answers

Why is Python's Hashlib not strongly typed?

Python is supposed to be strongly typed. For instance: 'abc'['1'] won't work, because you're expected to provide an integer there, not a string. An error wil be raised and you can go on and correct it. But that's not the case with hashlib. Indeed,…
Thomas Orozco
  • 45,796
  • 9
  • 97
  • 109
4
votes
2 answers

Errors running gcloud, was working fine till yesterday

Yesterday, gcloud was working completely fine. And today, it's throwing this error. I'm quite sure I haven't changed anything to cause this. Does anybody have any idea what this could be? 1) I've exported CLOUDSDK_PYTHON to be the python2 path. I…
DUDANF
  • 1,890
  • 6
  • 25
4
votes
0 answers

Instagram Scraping with endpoints requires authentication for all requests

As you know, Instagram announced they has changed their endpoint apis this month. Looks like in the wake of Cambridge Analytica instagram has changed up their endpoint formats and require a logged in user session for all requests..... Not sure which…
Top Coder
  • 360
  • 1
  • 3
  • 13
4
votes
2 answers

_sha import in python hashlib

Well, today I was checking the hashlib module in python, but then I found something that I still can't figure out. Inside this python module, there is an import that I can't follow. I goes like this: def __get_builtin_constructor(name): if name…
FernandoEscher
  • 2,700
  • 2
  • 25
  • 27
4
votes
2 answers

Python: How to create a 16 character long digest using hashlib.md5 algorithm?

Php's md5 function takes an optional second argument which, if true, returns a smaller hash of length 16 instead of the normal 32 character long hash. How can we do the same using python's hashlib.md5.
Adil Malik
  • 7,633
  • 9
  • 49
  • 80
4
votes
1 answer

Why I am getting this error(AttributeError: 'module' object has no attribute 'openssl_md_meth_names')?

So far there seems to be only one question regarding this error in the entire forum.. When running any pyo example in E-Pyo through Python 2.7.11 I get this error: File "C:\Python27\lib\site-packages\pyolib\_core.py", line 22, in import…
4
votes
2 answers

Is there any way to use non-openssl md5 for hashlib in python?

I generate md5 content hashes for upload verification, but it has recently come to my attention that this will fail for any users running on a FIPS enabled machine. FIPS disables openssl md5, resulting in a ValueError when I try to initialize…
Jordon Phillips
  • 11,056
  • 3
  • 31
  • 39
4
votes
1 answer

How to update hashlib.md5 hasher using existing hasher in python?

I have got cached instance of hasher: m1 = hashlib.md5() m1.update(b'very-very-long-data') cached_sum = m1 and I would like to update external hasher with a sum cached before: def append_cached_hash(external_hasher): # something like this …
Andrew
  • 1,430
  • 1
  • 14
  • 25
4
votes
5 answers

Persisting hashlib state

I'd like to create a hashlib instance, update() it, then persist its state in some way. Later, I'd like to recreate the object using this state data, and continue to update() it. Finally, I'd like to get the hexdigest() of the total cumulative run…
anthony
  • 37,914
  • 5
  • 50
  • 126
4
votes
2 answers

unsupported hash type when installing plone

I tried to install plone but I have a problem when I run the script install.sh. Here are the errors details: raise ValueError('unsupported hash type %s' % name) ValueError: unsupported hash type sha256 ERROR:root:code for hash sha384 was not…
user1499220
  • 409
  • 3
  • 12
  • 21
4
votes
3 answers

Remove all characters from a string who's ordinals are out of range

What is a good way to remove all characters that are out of the range: ordinal(128) from a string in python? I'm using hashlib.sha256 in python 2.7. I'm getting the exception: UnicodeEncodeError: 'ascii' codec can't encode character u'\u200e' in…
Chris Dutrow
  • 42,732
  • 59
  • 174
  • 243