热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

将简单的PHP代码转换为python

我想将我的PHP代码转换为python代码.可能吗$secret'segredo';Tomakethehashmoredifficulttoreproduce.

我想将我的PHP代码转换为python代码.可能吗

$secret = 'segredo'; // To make the hash more difficult to reproduce.
$path = '/p/files/top_secret.pdf'; // This is the file to send to the user.
$expire = 1096891200; // At which point in time the file should expire. time() + x; would be the usual usage.
$md5 = base64_encode(md5($secret . $path . $expire, true)); // Using binary hashing.`$md5 = strtr($md5, '+/', '-_'); // + and / are considered special characters in URLs, see the wikipedia page linked in references.
$md5 = str_replace('=', '', $md5); // When used in query parameters the base64 padding character is considered special.

我想将上面的PHP代码转换为python.是否存在一些转换工具?

此代码是nginx HttpSecureLinkModule的简单唯一url生成器.

解决方法:

import hashlib
secret, path, expire = 'segredo', '/p/files/top_secret.pdf', 1096891200
md5 = hashlib.md5(secret + path + str(expire)).digest().encode('base64').strip('\n=')


推荐阅读
author-avatar
sasame
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有