基于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) // Z/Gl0yMSttfh9jR9zWX7iw==
-
这是移植到python的代码
from crypto_py import CryptoPY as CryptoJS # 以下操作都相同 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 }).decode() print(encrypt) # Z/Gl0yMSttfh9jR9zWX7iw==
-
-
同时也支持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.1.0.tar.gz
(4.4 kB
view details)
Built Distribution
File details
Details for the file crypto_js_to_py-0.1.0.tar.gz
.
File metadata
- Download URL: crypto_js_to_py-0.1.0.tar.gz
- Upload date:
- Size: 4.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7646c44c9dfb8975d003b31d4cbf57964b35b3c575ad83f70a97c048d97d8321 |
|
MD5 | 01bc1f7611fdd788dee2760949ea5004 |
|
BLAKE2b-256 | 9453304064e2d308981b66a5fa4b26e6317bf08b0a34fa7aba5a0a7718667a3f |
File details
Details for the file crypto_js_to_py-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: crypto_js_to_py-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c4b31a87bee865e0205597150d24309472bd2b6e5152417a6429b730f3abc1ec |
|
MD5 | ef90d2525ae17e0f237b0b0678c8e243 |
|
BLAKE2b-256 | 509ffa541d732cfcec07213f0ac3de99f13e7975baf38f23acc33bac35879c5b |