V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
enj0y
V2EX  ›  Python

python2php

  •  
  •   enj0y · 2013-01-31 12:39:06 +08:00 · 3261 次点击
    这是一个创建于 4100 天前的主题,其中的信息可能已经有所发展或是发生改变。
    python里的
    hmac.new("key","data string to encrypt").hexdigest()
    转换成PHP
    hash_hmac()
    是怎样的算法?

    拜谢!
    5 条回复    1970-01-01 08:00:00 +08:00
    BigZ
        1
    BigZ  
       2013-01-31 13:51:19 +08:00
    python文档里面写的很清楚

    It defaults to the hashlib.md5() constructor.
    shiny
        2
    shiny  
       2013-01-31 13:56:31 +08:00   ❤️ 1
    so it should be
    hash_hmac("md5","data string to encrypt","key")

    python下的文档:http://docs.python.org/2/library/hmac.html
    php下的文档:http://php.net/manual/en/function.hash-hmac.php
    enj0y
        3
    enj0y  
    OP
       2013-01-31 13:59:53 +08:00
    @shiny hash_hmac('sha1',"data string to encrypt","key");
    is this ok?
    shiny
        4
    shiny  
       2013-01-31 14:07:04 +08:00   ❤️ 1
    @enj0y
    hmac.new(key[, msg[, digestmod]])
    python 下的 digestmod 默认是md5的,而php下没有默认摘要算法,所以翻译过来是md5。当然指定为sha1、sha256之类都是可以的。
    whtsky
        5
    whtsky  
       2013-01-31 14:08:55 +08:00
    我还以为是某个逆天的工具....
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1802 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 16:31 · PVG 00:31 · LAX 09:31 · JFK 12:31
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.