源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

Python加密方法小结【md5,base64,sha1】

  • 时间:2020-09-29 06:43 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:Python加密方法小结【md5,base64,sha1】
本文实例总结了python加密方法。分享给大家供大家参考,具体如下: [b]MD5加密:[/b]
def md5(str):
  import hashlib
  m = hashlib.md5()
  m.update(str)
  return m.hexdigest()

[b]base64加密:[/b]
import base64
s = '我是字符串'
a = base64.b64encode(s)
print a
print base64.b64decode(a)

输出结果:
ztLKx9fWt/u0rg==
我是字符串

[b]sha1加密:[/b] 需要导入hashlib 模块:
import hashlib
def str_encrypt(str):
  """
  使用sha1加密算法,返回str加密后的字符串
  """
  sha = hashlib.sha1(str)
  encrypts = sha.hexdigest()
  return encrypts

[b]PS:关于加密解密感兴趣的朋友还可以参考本站在线工具:[/b] [b]文字在线加密解密工具(包含AES、DES、RC4等): [/b][url=http://tools.jb51.net/password/txt_encode]http://tools.jb51.net/password/txt_encode[/url] [b]MD5在线加密工具: [/b][url=http://tools.jb51.net/password/CreateMD5Password]http://tools.jb51.net/password/CreateMD5Password[/url] [b]在线散列/哈希算法加密工具: [/b][url=http://tools.jb51.net/password/hash_encrypt]http://tools.jb51.net/password/hash_encrypt[/url] [b]在线MD5/hash/SHA-1/SHA-2/SHA-256/SHA-512/SHA-3/RIPEMD-160加密工具: [/b][url=http://tools.jb51.net/password/hash_md5_sha]http://tools.jb51.net/password/hash_md5_sha[/url] [b]在线sha1/sha224/sha256/sha384/sha512加密工具: [/b][url=http://tools.jb51.net/password/sha_encode]http://tools.jb51.net/password/sha_encode[/url] 更多关于Python相关内容感兴趣的读者可查看本站专题:《[url=http://www.1sucai.cn/Special/946.htm]Python加密解密算法与技巧总结[/url]》、《[url=http://www.1sucai.cn/Special/788.htm]Python编码操作技巧总结[/url]》、《[url=http://www.1sucai.cn/Special/663.htm]Python数据结构与算法教程[/url]》、《[url=http://www.1sucai.cn/Special/642.htm]Python函数使用技巧总结[/url]》、《[url=http://www.1sucai.cn/Special/636.htm]Python字符串操作技巧汇总[/url]》及《[url=http://www.1sucai.cn/Special/520.htm]Python入门与进阶经典教程[/url]》 希望本文所述对大家Python程序设计有所帮助。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部