zoukankan      html  css  js  c++  java
  • 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()

  • 相关阅读:
    java方法参数传值传引用的一点看法
    Oracle触发器介绍
    CASE WHEN
    group by ,order by ,having
    Java中使用正则表达式
    Oracle 9i 分析函数参考手册
    ORACLE round 与 trunc 的区别
    oracle的默认表名长度(30)
    order by 使用索引的情况
    解析oracle的ROWNUM 作者: chen_liang
  • 原文地址:https://www.cnblogs.com/lvxiuquan/p/2968430.html
Copyright © 2011-2022 走看看