zoukankan      html  css  js  c++  java
  • hashlib模块

    #hashlib模块

    • 摘要算法,也叫做加密算法,或者是哈希算法,散列算法等等,做加密和校验使用

    #md5 普通加密

    #md5普通加密

    import hashlib
    md5 = hashlib.md5()
    md5.update("LCh123456".encode("utf-8"))  #必须是bytes类型才能加密
    print(md5.hexdigest())
    >>>>d60861d4be2012e49709703fb7470a24
    ###相同的bytes数据的加密转换一定是相同的
    

    #md5 + 固定加盐

    md5 = hashlib.md5('要加的盐'.encode('utf-8'))  #'爸爸' 就是加的盐
    md5.update("要加密的内容".encode("utf-8"))
    print(md5.hexdigest())
    >>>97d56646f57a6a24041f3c84a2eaab6e
    

    #md5 + 动态的盐

    username = input("请输入用户")
    md5 = hashlib.md5(username[::2].encode("utf-8"))  #不同的用户加入不同的盐
    md5.update("要加密的内容".encode("utf-8"))
    print(md5.hexdigest())
    ###输入不同数据加不同的盐
    

    #sha1,sha224,sha512等

    #sha1普通加密

    ret = hashlib.sha1()
    ret.update("要加密的内容".encode("utf-8"))
    print(ret.hexdigest())
    >>>8046e81fa5904f03f9c3165aaf5b47ee1ae54d8b
    

    #sha1 + 固定加盐

    ret = hashlib.sha1(b'asdasd')
    ret.update("要加密的内容".encode("utf-8"))
    print(ret.hexdigest())
    >>>a97c79a519bdc266f2c66986ce08b0c4b53692fc
    

  • 相关阅读:
    Rotation Kinematics
    离职 mark
    PnP 问题方程怎么列?
    DSO windowed optimization 代码 (4)
    Adjoint of SE(3)
    IMU 预积分推导
    DSO windowed optimization 代码 (3)
    DSO windowed optimization 代码 (2)
    OKVIS 代码框架
    DSO windowed optimization 代码 (1)
  • 原文地址:https://www.cnblogs.com/Nayears/p/12166638.html
Copyright © 2011-2022 走看看