gpt4 book ai didi

php mcrypt 三元组的 python 等效项

转载 作者:行者123 更新时间:2023-11-30 23:26:46 24 4
gpt4 key购买 nike

我有以下 PHP 函数来加密和解密数据。它们不是我自己写的。现在加密的数据存储在数据库中,我必须从那里读取它并使用 python 将其显示给用户。我尝试用谷歌搜索,但没有找到任何符合我需求的东西。

希望有人提示我从哪里开始或有用的链接。

function Decrypt($input) {
$key = "xxx"; // 18 Signs
$iv = "xxx"; // 8 Signs
return mcrypt_decrypt(MCRYPT_TRIPLEDES, $key, base64_decode($input), MCRYPT_MODE_ECB, $iv);
}

function Encrypt($input) {
$key = "xxx"; // 18 Signs
$iv = "xxx"; // 8 Signs
return base64_encode(mcrypt_encrypt(MCRYPT_TRIPLEDES, $key, $input, MCRYPT_MODE_ECB, $iv));
}

最佳答案

有一个Python interface to the standard mcrypt library 。它的文档...不是那么多...但我仔细研究了它并提出了一些我认为与您发布的 PHP 重复的代码:

import mcrypt
import base64

KEY = 'xxx'
IV = 'xxx'
ALGORITHM = 'tripledes'
MODE = 'ecb'

def encrypt(data):
cryptor = mcrypt.MCRYPT(ALGORITHM, MODE)
cryptor.init(KEY, IV)
return base64.b64encode(cryptor.encrypt(data))

def decrypt(data):
cryptor = mcrypt.MCRYPT(ALGORITHM, MODE)
cryptor.init(KEY, IV)
return cryptor.decrypt(base64.b64decode(data))

关于php mcrypt 三元组的 python 等效项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22382542/

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