CryptoJS中AES加密Python实现的问题
本帖最后由 天黑我隐身 于 2020-4-27 21:59 编辑JS加密代码如上图,使用CryptoJS AES加密,我对加解密算法是个门外汉,一番google百度之后大致分析出t是key(固定的),e是要加密的数据
然后使用pycrypto编写加密函数
```python
from Crypto.Cipher import AES
import base64
def encrypt(text):
BS = AES.block_size
pad = lambda s: s + (BS - len(s) % BS) * chr(BS - len(s) % BS)
key = '1c52a966appsapi0'
encryptor = AES.new(key, AES.MODE_ECB)
ciphertext = encryptor.encrypt(pad(text))
ciphertext = base64.b64encode(ciphertext)
return ciphertext
```
但是当我输入加密文本e后,Python得出的结果和JS并不相同,所以请教一下各位,Python加密代码哪里不对吗
完整JS代码地址https://wappass.baidu.com/static/machine/js/api/mkd.js
测试加密文本
{"cl":[{"x":180,"y":260,"t":1587987234248},{"x":196,"y":410,"t":1587987235576}],"mv":[{"fx":213,"fy":25,"t":1587987233059},{"fx":213,"fy":26,"t":1587987233436},{"fx":206,"fy":45,"t":1587987233680},{"fx":220,"fy":92,"t":1587987233834},{"fx":196,"fy":232,"t":1587987234015},{"fx":180,"fy":260,"t":1587987234166},{"fx":180,"fy":260,"t":1587987234372},{"fx":180,"fy":260,"t":1587987234803},{"fx":181,"fy":264,"t":1587987234976},{"fx":187,"fy":361,"t":1587987235152},{"fx":180,"fy":429,"t":1587987235318},{"fx":187,"fy":422,"t":1587987235483},{"fx":197,"fy":410,"t":1587987235771}],"sc":[],"kb":[{"key":"a","t":1587987234920},{"key":"a","t":1587987234979},{"key":"a","t":1587987235101},{"key":"a","t":1587987235191},{"key":"a","t":1587987235224},{"key":"a","t":1587987235314}],"cr":{"screenTop":23,"screenLeft":0,"clientWidth":323,"clientHeight":582,"screenWidth":1280,"screenHeight":800,"availWidth":1280,"availHeight":708,"outerWidth":1280,"outerHeight":708,"scrollWidth":1100,"scrollHeight":1100},"simu":0,"ac_c":0}
Python加密结果
2bQbjHMq7u6k40l96DDGGFSE8wVQt/r+XoyzMeBDIhNtNAPUoL2J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fWIje8oQ6vAAhTy8oz5L2Rif9nh/QTTe/nmV1IdHDJJMUA4zwrsM67hL1yo2DcKSVV8l2WsVAKGmu9k4LahHfVEaobY/oP0tS8KzyCasinQ3v55PyOFK24KnMEOuzSHCwbCHYoiHT2T4vc1OFVtmfog2NOTzCjRtm7Z5bTRclEaCCCFSz0K702pGOXErguW/SEiG2gJzEnOZ0Xj2hrfMUdQwohw0t2E6Vjlymf5UBccBeeErJyTtJmvABhI7rWiGuly5lel9IZur+vGvd/tZG4XIdPaqTVCkABXFfUptHTwpaA9cOApN2v6wKwddjd0CE3ep/eyQKXkdASpT4kK6iEjWcJqt+u3iBgzSJ1GhJoDVHJaWU15t3BWCk1ChE89NAYzMWke8xruECsXvpjUGpVcYM8ZPlc2BYd/cKa2Qo7zB7w21gD7782XxxLWVzAAFNPfXX6YRjCtKrHLvomVQb/lce3eucd8X287E0DO6fupEmifBS+VasDjwUT0kZzCbZ1N/3G2+pgNq7fd6btNUgTumsQA==
对不起各位,当我发完帖子的时候突然发现到key并不是固定的...使用一致的key得到的加密结果一致,打扰了 看着那么眼熟,原来我以前解密别人api的时候用过。python的代码和js的代码差不多。 RemMai 发表于 2020-4-27 20:12
看着那么眼熟,原来我以前解密别人api的时候用过。python的代码和js的代码差不多。
哈哈哈,我快被百度二十多个请求参数和恶心的JS混淆搞疯了
页:
[1]