Questions tagged [hashlib]

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

361 questions
7
votes
2 answers

Compare md5 hashes of two files in python

I want to compare hashes of two files. But no matter if files are different or not, even with different hashes comparison results True Here is the code: import hashlib hasher1 = hashlib.md5() afile1 = open('canvas.png', 'rb') buf1 =…
VAGrus
  • 73
  • 1
  • 1
  • 6
7
votes
3 answers

Python SHA1 Integer

I did two SHA1 in C code, one is for a string, and another is for a integer, and get different result. SHA_init(&ctx); SHA_update(&ctx, "1234", 4); sha = SHA_final(&ctx); unsigned n = 1234; SHA_init(&ctx); SHA_update(&ctx, &n, sizeof(n)); sha =…
Weicuan Yan
  • 71
  • 1
  • 5
7
votes
2 answers

Convert unique numbers to md5 hash using pandas

Good morning, All. I want to convert my social security numbers to a md5 hash hex number. The outcome should be a unique md5 hash hex number for each social security number. My data format is as follows: ob =…
Dave
  • 4,937
  • 5
  • 21
  • 26
7
votes
1 answer

HMAC signing requests in Python

I'm trying to create an HMAC-SHA512 signed request for an API call in Python 3.4 using the requests library. I'm trying to follow docs, but am hitting this error: AttributeError: '_hashlib.HASH' object has no attribute 'new' Here's some code. It's…
Ludo
  • 2,437
  • 2
  • 26
  • 37
7
votes
4 answers

Python shortest unique id from strings

I have more than 100 million unique strings (VARCHAR(100) UNIQUE in MySQL database). Now I use the code below to create unique hash from them (VARCHAR(32) UNIQUE) in order to reduct index size of the InnoDB table (a unique index on varchar(100) is…
jack
  • 15,121
  • 32
  • 94
  • 122
6
votes
3 answers

Hashlib hashes not comparing properly

Heres my code: import hashlib real = hashlib.sha512("mom") status = True while status: inp = raw_input("What's the password?") converted = hashlib.sha512(inp) if converted == real: print "Access granted!" status =…
user775171
6
votes
3 answers

What is _md5.md5 and why is hashlib.md5 so much slower?

Found this undocumented _md5 when getting frustrated with the slow stdlib hashlib.md5 implementation. On a macbook: >>> timeit hashlib.md5(b"hello world") 597 ns ± 17.2 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each) >>> timeit…
wim
  • 266,989
  • 79
  • 484
  • 630
6
votes
1 answer

How to get the same hash in Python3 and Mac / Linux terminal?

How can I get the same sha256 hash in terminal (Mac/Linux) and Python? Tried different versions of the examples below, and search on StackOverflow. Terminal: echo 'test text' | shasum -a…
Punnerud
  • 3,630
  • 1
  • 36
  • 32
6
votes
3 answers

SHA 512 crypt output written with Python code is different from mkpasswd

Running mkpasswd -m sha-512 -S salt1234 password results in the following: $6$salt1234$Zr07alHmuONZlfKILiGKKULQZaBG6Qmf5smHCNH35KnciTapZ7dItwaCv5SKZ1xH9ydG59SCgkdtsTqVWGhk81 I have this snippet of Python code that I thought would output the same,…
user1720897
  • 1,035
  • 2
  • 9
  • 21
6
votes
1 answer

Securely overwrite Python variables in RAM?

I'm making a program in Python that will involve hashing a password. Assuming I use this to get the password: import getpass password = getpass.getpass("Password: ") And then hash it, is there any way to securely remove all traces of the unhashed…
tkbx
  • 13,156
  • 26
  • 77
  • 116
6
votes
6 answers

the fastest way to create checksum for large files in python

i need to transfer large files across network and need to create checksum for them on hourly basis. so the speed for generating checksum is critical for me. somehow i can't make zlib.crc32 and zlib.adler32 working with files larger than 4GB on…
pixelblender
  • 171
  • 2
  • 4
  • 8
5
votes
5 answers

Unable to import "hashlib"

I'm trying to encrypt a string in sha1 and I get an error from the server: "No Module Named hashlib" By using the following code: import hashlib encrypted = hashlib.sha1(string) encrypted = encrypted.digest() I'll appreciate any help, Thanks, Guy…
user330885
5
votes
1 answer

How do I create a signature numerical for OneHotEncoded values and hashlibs in python?

I want to assign a numberical digit to onehotencoded values in my dataframe: import pandas as pd scale = df.ServiceSubCodeKey.max() + 1 onehot = [] for claimid, ssc in df.groupby('ClaimId').ServiceSubCodeKey: ssc_list = ssc.to_list() …
Joe Tha
  • 498
  • 1
  • 10
5
votes
3 answers

Invalid hash, timestamp, and key combination in Marvel API Call

I'm trying to form a Marvel API Call. Here's a link on authorization: https://developer.marvel.com/documentation/authorization I'm attempting to create a server-side application, so according to the link above, I need a timestamp, apikey, and hash…
5
votes
3 answers

Python and hashlib module

I've just installed Python 2.6.6 from sources and what I get: >>> import hashlib Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python2.6/hashlib.py", line 136, in md5 =…
zerkms
  • 230,357
  • 57
  • 408
  • 498
1 2
3
24 25