基于pycryptodomex的二次封装,对CryptoJS的AES和CBC进行了简单的复刻
Project description
介绍
这是一个crypto-js的Python复刻版,对ECB和CBC进行了简单的复刻
安装与导入
pip install crypto-js-to-py
from crypto_py import CryptoPY
代码示例
-
一个简单的crypto-js移植python的示例代码
-
这是一段crypto-js的示例代码
const CryptoJS = require("crypto-js") key = CryptoJS.enc.Utf8.parse("1234567890123456") iv = CryptoJS.enc.Utf8.parse("1234567890123456") data = "我是帅哥" encrypt = CryptoJS.AES.encrypt(data,key,{ "iv": iv, "mode":CryptoJS.mode.CBC, "padding":CryptoJS.pad.Pkcs7 }).toString() console.log(encrypt)
-
这是移植到python的代码
from crypto_py import CryptoPY as CryptoJS # 以下操作都相同 key = CryptoJS.enc.Utf8.parse("1234567890123456") iv = CryptoJS.enc.Utf8.parse("1234567890123456") data = "我是帅哥" # 这里的options也可以通过对象的方式传入 # options = CryptoJS.Options( # iv=iv, # mode=CryptoJS.mode.CBC, # padding=CryptoJS.pad.Pkcs7 # ) # encrypt = CryptoJS.AES.encrypt(data,key,options).decode() encrypt = CryptoJS.AES.encrypt(data,key,{ "iv": iv, "mode":CryptoJS.mode.CBC, "padding":CryptoJS.pad.Pkcs7 }).decode() print(encrypt)
-
-
同时也支持NoPadding和ciphertext
CryptoPY.pad.NoPadding暂时未能测试是否无BUGCryptoPY.AES.encrypt(...).ciphertext.decode()CryptoPY.AES.decrypt(...).ciphertext.decode()
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
crypto-js-to-py-0.2.2.tar.gz
(9.4 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file crypto-js-to-py-0.2.2.tar.gz.
File metadata
- Download URL: crypto-js-to-py-0.2.2.tar.gz
- Upload date:
- Size: 9.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
75c69662dcdd5c65f422e5566b363f19bcb0a6ebcce3e8abf27b114fb6b8b1e7
|
|
| MD5 |
8961234e90d6160ed1a6bcaf73d8c8d2
|
|
| BLAKE2b-256 |
68b9218341e799955d3ec155c4004e1f330630d6a8fd6fcf5d020fcd78a0e3fe
|
File details
Details for the file crypto_js_to_py-0.2.2-py3-none-any.whl.
File metadata
- Download URL: crypto_js_to_py-0.2.2-py3-none-any.whl
- Upload date:
- Size: 13.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6818ba6fb96de1564cb2c4f1363901ba5800587e977df79f70d21178d855b9fb
|
|
| MD5 |
d894acd52dbd2ff7bd279a5207d67327
|
|
| BLAKE2b-256 |
d8f130a72febe7716900e4bc400e3d89162228dbcc2bacdf4abd0b2711b3e87f
|