1、强大的hashlib,提供了用于加密相关的操作,代替了md5模块和sha模块,主要提供 SHA1, SHA224, SHA256, SHA384, SHA512 ,MD5 算法

2、hmac模块实现了hmac算法,需要一个key来进行加密,提供更为强大的加密,不过需要提供key,也就是通常说的盐

3、使用hashlib.algorithms_available,可以查看hashlib提供的加密算法

4、加密的算法的一般使用,但时候存在缺陷,即:通过撞库可以反解

# ######## md5 ########
hash = hashlib.md5()  #创建md5()加密实例
hash.update(bytes('admin', encoding='utf-8'))  #对admin字符进行加密
print(hash.hexdigest()) #返回产生的十六进制的bytes
print(hash.digest()) 
 
 
######## sha1 ########
 
hash = hashlib.sha1()
hash.update(bytes('admin', encoding='utf-8'))
print(hash.hexdigest())
 
# ######## sha256 ########
 
hash = hashlib.sha256()
hash.update(bytes('admin', encoding='utf-8'))
print(hash.hexdigest())
 
 
# ######## sha384 ########
 
hash = hashlib.sha384()
hash.update(bytes('admin', encoding='utf-8'))
print(hash.hexdigest())
 
# ######## sha512 ########
 
hash = hashlib.sha512()
hash.update(bytes('admin', encoding='utf-8'))
print(hash.hexdigest())
 1 Hash objects have these methods:
 2  - update(arg): Update the hash object with the bytes in arg. Repeated calls
 3                 are equivalent to a single call with the concatenation of all
 4                 the arguments.
 5  - digest():    Return the digest of the bytes passed to the update() method
 6                 so far.
 7  - hexdigest(): Like digest() except the digest is returned as a unicode
 8                 object of double length, containing only hexadecimal digits.
 9  - copy():      Return a copy (clone) of the hash object. This can be used to
10                 efficiently compute the digests of strings that share a common
11                 initial substring.
官方说明

相关文章:

  • 2022-12-23
  • 2022-02-10
  • 2022-02-05
  • 2022-01-30
  • 2022-01-30
  • 2021-08-10
  • 2022-01-15
  • 2021-10-06
猜你喜欢
  • 2022-12-23
  • 2021-12-14
  • 2022-12-23
  • 2022-12-23
  • 2021-10-02
  • 2021-08-16
相关资源
相似解决方案