栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

Python 安装 Crypto

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Python 安装 Crypto

Python 安装 Crypto

今天在用 python 写 小程序需要解密时,需要安装 Crypto 使用 AES 对登录的信息进行解密

warning: GMP or MPIR library not found; Not building Crypto.PublicKey._fastmath.
    building 'Crypto.Random.OSRNG.winrandom' extension
    error: Microsoft Visual C++ 14.0 is required. Get it with "Build Tools for Visual Studio": https://visualstudio.microsoft.com/downloads/
    ----------------------------------------
ERROR: Command errored out with exit status 1: 'D:Program Filespython3.8python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\auth\AppData\Local\Temp\pip-install-lmxibyso\pycrypto\setup.py'"'"'; __file__='"'"'C:\Users\auth\AppData\Local\Temp\pip-install-lmxibyso\pycrypto\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'rn'"'"', '"'"'n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:UsersauthAppDataLocalTemppip-record-ii2jkae9install-record.txt' --single-version-externally-managed --compile --install-headers 'D:Program Filespython3.8Includepycrypto' Check the logs for full command output.

找了很多方法
我试了更新 pip,试了卸载重装,试了 安装 pycrypto 编译好的 exe 安装包(不知道是不是因为版本不对,最后已失败告终),,,
终于还是发现了一个 可以用的
https://www.cnblogs.com/steinven/p/11216361.html

python 在 Windows下使用AES时要安装的是pycryptodome 模块

pip install pycryptodome

python 在 Linux下使用AES时要安装的是pycrypto模块

pip install pycrypto

终于解开了小程序的加密信息

# 微信官方 提供的 解密 demo
import base64
import json
from Crypto.Cipher import AES

class WXBizDataCrypt:
    def __init__(self, appId, sessionKey):
        self.appId = appId
        self.sessionKey = sessionKey

    def decrypt(self, encryptedData, iv):
        # base64 decode
        sessionKey = base64.b64decode(self.sessionKey)
        encryptedData = base64.b64decode(encryptedData)
        iv = base64.b64decode(iv)

        cipher = AES.new(sessionKey, AES.MODE_CBC, iv)

        decrypted = json.loads(self._unpad(cipher.decrypt(encryptedData)))

        if decrypted['watermark']['appid'] != self.appId:
            raise Exception('Invalid Buffer')

        return decrypted

    def _unpad(self, s):
        return s[:-ord(s[len(s)-1:])]
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/833387.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号