zoukankan      html  css  js  c++  java
  • python学习笔记5--加密模块hashlib

    import hashlib
    # md5
    ybm_pwd='yuanbapqingsdfs234FF234HF@F' #
    m = hashlib.md5() #
    bytes_ybq = ybm_pwd.encode()#把字符串转成bytes类型
    m.update(bytes_ybq) #加密,不能字符串,只能传bytes类型,二进制
    # print(m.hexdigest()) #加密后的结果
    
    def md5_password(st:str):#限定了入参的类型,只能为string类型
        bytes_st = st.encode() #转成二进制类型
        m = hashlib.md5(bytes_st) #加密
        return m.hexdigest() #返回加密后的结果
    
    
    sha_256 =hashlib.sha256(bytes_ybq)
    sha512 =hashlib.sha512(bytes_ybq)
    print(sha512.hexdigest())
    
    # print(dir(m))
    
    #md5加密是不可逆的,不能被解密的。
    MD5            md5AF
    123456        f0dfb4c958c67903e542e31c729c629b
    
    撞库
    
    import base64
    s='hahaha'
    byte_s = s.encode() #字符串变成二进制
    res = base64.b64encode(byte_s) #base64编码
    print(res.decode()) #把bytes转成字符串。
    jie_mi_res = base64.b64decode(res.decode()) #base64编码
  • 相关阅读:
    HashMap
    java反射
    arraylist和linkedlist区别
    int和Integer的区别
    java 数组排序并去重
    矩阵链乘法问题
    找零问题
    硬币收集问题
    最大借书量问题
    钢条切割问题
  • 原文地址:https://www.cnblogs.com/SuKiWX/p/8946248.html
Copyright © 2011-2022 走看看