gpt4 book ai didi

php - 将简单的php代码转换为python

转载 作者:可可西里 更新时间:2023-11-01 00:48:27 24 4
gpt4 key购买 nike

我想将我的 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=')

关于php - 将简单的php代码转换为python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12783233/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com