推荐学习书目
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 · Jan 31, 2013 · 4238 views
  •   You need to sign in to view this topic
    This topic created in 4928 days ago, the information mentioned may be changed or developed.
    python里的
    hmac.new("key","data string to encrypt").hexdigest()
    转换成PHP
    hash_hmac()
    是怎样的算法?

    拜谢!
    5 replies    1970-01-01 08:00:00 +08:00
    BigZ
        1
    BigZ  
       Jan 31, 2013
    python文档里面写的很清楚

    It defaults to the hashlib.md5() constructor.
    shiny
        2
    shiny  
    PRO
       Jan 31, 2013   ❤️ 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
       Jan 31, 2013
    @shiny hash_hmac('sha1',"data string to encrypt","key");
    is this ok?
    shiny
        4
    shiny  
    PRO
       Jan 31, 2013   ❤️ 1
    @enj0y
    hmac.new(key[, msg[, digestmod]])
    python 下的 digestmod 默认是md5的,而php下没有默认摘要算法,所以翻译过来是md5。当然指定为sha1、sha256之类都是可以的。
    whtsky
        5
    whtsky  
       Jan 31, 2013
    我还以为是某个逆天的工具....
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   4711 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 09:50 · PVG 17:50 · LAX 02:50 · JFK 05:50
    ♥ Do have faith in what you're doing.