Convert SHA-512 string to base64 in python
As we've seen in earlier posts, you can create an SHA-512 hash of a string and generate a hash in string type or let's say a case where you are using it on a file.
In the code below, we are going to encode the bytes-like object a.digest()
using Base64 and return a bytes object which will be stored in the variable b
.
import hashlib
import base64
a = hashlib.sha256('your string or password'.encode('utf8'))
b = base64.b64encode(a.digest()).decode()
print(b)
The output of the above code will be a base64 string-
SLTP9aqQMaZFQzEY4zzlvgXabQafQLTkC1s/Q0UXtj0=
I'm glad that you found this article to create a base64 string out of SHA-512 hash useful. Happy Coding.
Share this blog
Share
Like what you read?
Subscribe to our Newsletter
Subscribe to our email newsletter and unlock access to members-only content and exclusive updates.
About the Author
Satvik is a passionate developer turned Entrepreneur.
He is fascinated by JavaScript, Operating System, Deep Learning, AR/VR. He has published several research papers and applied for patents in the field as well.
Satvik is a speaker in conferences, meetups talking about Artificial Intelligence, JavaScript and related subjects.
His goal is to solve complex problems that people face with automation.
Related projects can be seen at - [Projects](/projects)
View all articles
Previous Article
Next Article