django, python和链接加密

2024-04-16 09:33:13 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要安排某种加密来生成特定于用户的链接。用户将单击此链接,在其他视图中,与加密字符串相关的链接将被解密并返回结果。

为此,我需要某种加密函数,该函数使用一个数字(或字符串),该数字(或字符串)是绑定到用户帐户的选定项的主键,同时还使用某种种子并生成将在其他页上解密的加密代码。

所以像这样的事情

my_items_pk = 36 #primary key of an item
seed = "rsdjk324j23423j4j2" #some string for crypting
encrypted_string = encrypt(my_items_pk,seed)
#generates some crypted string such as "dsaj2j213jasas452k41k"
and at another page:
decrypt_input = encrypt(decypt,seed)
print decrypt_input
#gives 36

我希望我的“seed”是某种主变量(而不是某个类),用于此目的(例如一些数字或字符串)。

如何在python和django下实现这一点?


Tags: 函数字符串用户视图inputstring链接my