Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2842584
  • 博文数量: 348
  • 博客积分: 2907
  • 博客等级: 中校
  • 技术积分: 2272
  • 用 户 组: 普通用户
  • 注册时间: 2010-03-12 09:16
个人简介

专注 K8S研究

文章分类

全部博文(348)

文章存档

2019年(22)

2018年(57)

2016年(2)

2015年(27)

2014年(33)

2013年(190)

2011年(3)

2010年(14)

分类: 网络与安全

2013-06-29 23:05:36

python的base64加密解密及常见数字签名算法

 

转自:http://my.oschina.net/eddit/blog/13894 有修改

 

Pythonhashlib模块里面包含了多种哈希算法,包括了验证文件完整性的md5,sha家族数字签名算法,还有常用的base64加密算法包含于base64模块中。

 

#! /usr/bin/env python

import hashlib

import base64


a = "a test string"
print hashlib.md5(a).hexdigest() #hexdigest()转换为16进制的字符串
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()


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

------------------------------
>>> print encoded
aGFoYQ==
>>> print decoded
haha

 

阅读(2039) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~