• PYTHON 加密相关模块


    #-*- coding:utf-8 -*-
    from hashlib import md5
    content = 12
    content_str = str(content)
    ciphertext = md5(content_str).hexdigest() #加密
    print ciphertext

    #from hashlib import md5
    #ciphertext_str=raw_input() #写入要解密的密文,如827ccb0eea8a706c4c34a16891f84e7b
    #MD5是不可逆的密码加密,可以说除了暴力破解外无法还原,但同样的输入加密出来的结果是一致的,因此要比较输入是否正确,只要比较一下加密后的结果即可,而Python中可以使用hashlib进行MD5加密,具体方法如下

    for i in xrange(100000):
    ciphertext_tmp = md5(str(i)).hexdigest()
    if ciphertext_tmp == ciphertext:
    print 'the password is %d' % i
    break

    python的base64加密解密及md5加密

    import hashlib

    a = "a test string"
    print hashlib.md5(a).hexdigest()
    print hashlib.sha1(a).hexdigest()
    print hashlib.sha224(a).hexdigest()
    print hashlib.sha256(a).hexdigest()
    print hashlib.sha384(a).hexdigest()
    print hashlib.sha512(a).hexdigest()

    import base64
    str='haha'
    encoded = base64.b64encode(str)
    decoded = base64.b64decode(encoded)

    1、hashlib
    import hashlib
    #创建一个哈希对象
    md = hashlib.md5()
    #md = hashlib.sha1()
    #md = hashlib.sha224()
    #md = hashlib.sha25()
    #md = hashlib.sha384()
    #md = hashlib.sha512()
    1.1 hashlib.update(arg)
    1.2 hashlib.digest() #返回数字形式的哈希
    1.3 hashlib.hexdigest() #返回16进制的哈希
    1.4 hashlib.copy()
    一般而言,用hashlib.hexdigest()就可以了
    2、hmac
    2.1 hmac.new(key[, msg[, digestmod]])
    2.2 hmac.update(msg)
    2.3 hmac.digest()
    2.4 hmac.hexdigest()
    2.5 hmac.copy()

  • 相关阅读:
    python-创建一个登录判断的函数
    python-创建一个本地txt文本
    python-简单函数小例子 单位转换
    微信小程序性能测试之jmeter踩坑记录(四)
    手动添加Keil的固件包Packs
    使用Socket的简单Web服务器
    网络端口(port)
    Redis 5种主要数据类型和命令
    c# 索引器方法
    .net 获取类型的Type类型的几种方法
  • 原文地址:https://www.cnblogs.com/lvxiuquan/p/2968430.html
Copyright © 2020-2023  润新知