基于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.1.tar.gz
(9.1 kB
view details)
Built Distribution
File details
Details for the file crypto-js-to-py-0.2.1.tar.gz
.
File metadata
- Download URL: crypto-js-to-py-0.2.1.tar.gz
- Upload date:
- Size: 9.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e8b08d91c0e0dd6ec2293dd3a59c4b1aeaad310c49ef3a04aa5611e2b10238dd |
|
MD5 | 2c9de302cfc74ded0d93c74fc1292be4 |
|
BLAKE2b-256 | c0b0fa30a199cae18a8c2eec3dfce3f84e83203ee59c981a1c0f29e59c61e774 |
File details
Details for the file crypto_js_to_py-0.2.1-py3-none-any.whl
.
File metadata
- Download URL: crypto_js_to_py-0.2.1-py3-none-any.whl
- Upload date:
- Size: 13.4 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 | b73c9d9b364e8b4593ab71a2a8b6abacad4dff8e55c1bc58f35c7d2cb20c573d |
|
MD5 | d5b19b0700fa1fe423861b3bcc0778a3 |
|
BLAKE2b-256 | c81b01ae448e78b0218304764379b8e063941eaf46e80f50fd0a9e17e2d0e421 |