python2php

2013-01-31 12:39:06 +08:00
 enj0y
python里的
hmac.new("key","data string to encrypt").hexdigest()
转换成PHP
hash_hmac()
是怎样的算法?

拜谢!
3269 次点击
所在节点    Python
5 条回复
BigZ
2013-01-31 13:51:19 +08:00
python文档里面写的很清楚

It defaults to the hashlib.md5() constructor.
shiny
2013-01-31 13:56:31 +08:00
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
2013-01-31 13:59:53 +08:00
@shiny hash_hmac('sha1',"data string to encrypt","key");
is this ok?
shiny
2013-01-31 14:07:04 +08:00
@enj0y
hmac.new(key[, msg[, digestmod]])
python 下的 digestmod 默认是md5的,而php下没有默认摘要算法,所以翻译过来是md5。当然指定为sha1、sha256之类都是可以的。
whtsky
2013-01-31 14:08:55 +08:00
我还以为是某个逆天的工具....

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/59365

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX