SoFunction
Updated on 2024-10-29

Python encryption methods summary [md5, base64, sha1

This article example summarizes python encryption methods. Shared for your reference, as follows:

MD5 encryption:

def md5(str):
  import hashlib
  m = hashlib.md5()
  (str)
  return ()

base64 encryption:

import base64
s = 'I'm a string'
a = base64.b64encode(s)
print a
print base64.b64decode(a)

Output results:

ztLKx9fWt/u0rg==
I'm a string.

sha1 encryption:

The hashlib module needs to be imported:

import hashlib
def str_encrypt(str):
  """
  Return str encrypted string using sha1 encryption algorithm
  """
  sha = hashlib.sha1(str)
  encrypts = ()
  return encrypts

PS: About encryption and decryption of friends interested in this site can also refer to online tools:

Text online encryption and decryption tools (including AES, DES, RC4, etc.):
http://tools./password/txt_encode

MD5 Online Encryption Tool.
http://tools./password/CreateMD5Password

Online hash/hash algorithm encryption tool.
http://tools./password/hash_encrypt

Online MD5/hash/SHA-1/SHA-2/SHA-256/SHA-512/SHA-3/RIPEMD-160 encryption tool:
http://tools./password/hash_md5_sha

Online sha1/sha224/sha256/sha384/sha512 encryption tool:
http://tools./password/sha_encode

Readers interested in more Python related content can check out this site's topic: theSummary of Python encryption and decryption algorithms and techniques》、《Summary of Python coding manipulation techniques》、《Python Data Structures and Algorithms Tutorial》、《Summary of Python function usage tips》、《Summary of Python string manipulation techniquesand thePython introductory and advanced classic tutorials

I hope that what I have said in this article will help you in Python programming.