1 Star 0 Fork 0

chinapyg/PyCryptoDemo

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
HashTest.py 1.61 KB
一键复制 编辑 原始数据 按行查看 历史
piaoyunsoft 提交于 2016-11-11 18:03 . 增加HashTest
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Date : 2016-11-11 16:38:36
# @Author : PiaoYun (piaoyunsoft@163.com)
# @Link : http://www.dllhook.com
# @Version : $Id$
import hmac
import hashlib
from Crypto.Hash import HMAC
from Crypto.Hash import MD2
from Crypto.Hash import MD4
from Crypto.Hash import MD5
from Crypto.Hash import RIPEMD
from Crypto.Hash import SHA
from Crypto.Hash import SHA224
from Crypto.Hash import SHA256
from Crypto.Hash import SHA384
from Crypto.Hash import SHA512
message = b"www.chinapyg.com"
def defaultHMAC():
h = hmac.new(b'piaoyun')
h.update(message)
print h.hexdigest().upper()
def pyCryptoHMAC():
secret = b'piaoyun'
h = HMAC.new(secret)
h.update(message)
print h.hexdigest().upper()
def _MD(type):
h = None
if type == 2:
h = MD2.new()
elif type == 4:
h = MD4.new()
elif type == 5:
h = MD5.new()
h.update(message)
print h.hexdigest().upper()
def _RIPEMD():
h = RIPEMD.new()
h.update(message)
print h.hexdigest().upper()
def _SHA(type):
h = None
if type == 1:
h = SHA.new()
elif type == 224:
h = SHA256.new()
elif type == 256:
h = SHA256.new()
elif type == 384:
h = SHA384.new()
elif type == 512:
h = SHA512.new()
h.update(message)
print h.hexdigest().upper()
if __name__ == '__main__':
print("====HMAC Test====")
defaultHMAC()
pyCryptoHMAC()
print("====MD Test====")
_MD(2)
_MD(4)
_MD(5)
print("====RIPEMD Test====")
_RIPEMD()
print("====SHA Test====")
_SHA(1)
_SHA(224)
_SHA(256)
_SHA(384)
_SHA(512)
print("====hashlib Test====")
h = hashlib.md5()
h.update(message)
print h.hexdigest().upper()
print h.digest().encode('hex').upper()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/chinapyg/PyCryptoDemo.git
git@gitee.com:chinapyg/PyCryptoDemo.git
chinapyg
PyCryptoDemo
PyCryptoDemo
master

搜索帮助