user9916289
user9916289

Reputation:

how to convert PHP hash into Python

I can create random salt using PHP and it works great. Below is my php code

$random_salt = hash('sha512', uniqid(openssl_random_pseudo_bytes(16), TRUE));

this generate 128 character like below

647366c3950b5fa89d6c71eaa9933c0e8cdf3e09b903641db41fdfe2591cef92aac46cc7b3b36c664bdbe4544aa24476eecbe19b21317c733e970998563e6a50

How can i achieve that in Python?

Upvotes: 0

Views: 133

Answers (1)

user13844806
user13844806

Reputation:

Here is the solution what you want in python

import uuid
import hashlib

def random_salt():
    s =  uuid.uuid4().hex
    s = hashlib.sha512(str(s).encode('utf-8')).hexdigest()
    return s

print(random_salt())

example output

aa8434ae552feb1421ec4a4a7273b10d3daebf15eaf0620cc61ce1e5d8bd3439f3ab0b23c7048bfa95071fc20c6244269fbfab68af024b6b3d30e393e31209e1

this will generate unique salt in 128 character every time

Upvotes: 1

Related Questions