zoukankan      html  css  js  c++  java
  • Python中hashlib模块的使用

    hashlib是 python 下一款与加密相关的库包,提供摘要算法:md5、sha1、sha224、sha256、sha384、sha512、blake2b、blake2s、sha3_224、sha3_256、sha3_384、sha3_512、shake_128、shake_256。摘要算法通过摘要函数(单向函数)对任意长度的数据计算出固定长度的摘要,目的是为了验证原始数据是否被篡改。

    MD5函数的使用,其他函数类似

    import hashlib
    #方法一
    m=hashlib.md5()
    m.update(b"root")      #提供的字符需要字节类型的
    print(m.digest)        #返回一个btye类型的md5值
    print(m.hexdigest())   #返回一个str类型的md5值
    print("*"*30)
    #方法二
    print(hashlib.md5(b"root").hexdigest())
    print("*"*30)
    #方法三:
    n=hashlib.new("md5")
    n.update(b"root")
    print(n.hexdigest())   #返回一个str类型的md5值
    print("*"*30)
    #方法四
    x=hashlib.new("md5",b"root").hexdigest()
    print(x)

    import hashlib
    
    print(hashlib.md5(b"root").hexdigest())
    print(hashlib.sha1(b"root").hexdigest())
    print(hashlib.sha224(b"root").hexdigest())
    print(hashlib.sha256(b"root").hexdigest())
    print(hashlib.sha384(b"root").hexdigest())
    print(hashlib.sha512(b"root").hexdigest())
    print(hashlib.sha3_224(b"root").hexdigest())
    print(hashlib.sha3_256(b"root").hexdigest())
    print(hashlib.sha3_384(b"root").hexdigest())
    print(hashlib.sha3_512(b"root").hexdigest())

  • 相关阅读:
    2019.04.19 坦克大战
    2019.04.18 异常和模块
    2019.04.17 面向对象编程篇207
    fork操作时的copy-on-write策略
    Redis阻塞原因
    Redis持久化-fork操作
    Redis持久化-AOF重写
    Redis持久化-aof
    Redis持久化
    Shopify给左右两边布局的banner图加链接,链接失败
  • 原文地址:https://www.cnblogs.com/csnd/p/11807600.html
Copyright © 2011-2022 走看看