https://github.com/exp-codes/pyc-cross-crypto
python & c++ 跨平台加解密
https://github.com/exp-codes/pyc-cross-crypto
aes cpp crypto des programming python
Last synced: 7 months ago
JSON representation
python & c++ 跨平台加解密
- Host: GitHub
- URL: https://github.com/exp-codes/pyc-cross-crypto
- Owner: EXP-Codes
- License: apache-2.0
- Created: 2023-05-23T15:37:40.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2023-07-05T05:22:38.000Z (over 2 years ago)
- Last Synced: 2025-04-03T16:49:12.326Z (12 months ago)
- Topics: aes, cpp, crypto, des, programming, python
- Language: C++
- Homepage:
- Size: 16.9 MB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# pyc-cross-crypto
> python & c++ 跨平台加解密
------
## 0x00 前言
由于 python 和 C++ 的 AES/DES 填充算法存在细微差异(应该说是第三方库存在差异),默认情况下, crypto++、pycryptodome、pyDes 即使 key、iv、编码 等等都一致的情况下,彼此所生成的密文是无法相互解密的。
这直接导致了跨平台加解密非常麻烦。苦于目前网上并没有现成的跨平台加解密,故有了此工程。
> 其实各个语言的实现都不尽相同,例如在数据本身已对齐 BLOCKSIZE 的情况下会不会再填充一个 BLOCK ,IV 是否强制使用随机等。
## 0x10 环境说明
 
## 0x20 核心文件
### 0x21 C++
- AES(依赖 [crypto++](./cpp/cryptopp/)):
- [aes_crypto.hpp](./cpp/aes_crypto.hpp)
- [aes_crypto.cpp](./cpp/aes_crypto.cpp)
- DES(依赖 [crypto++](./cpp/cryptopp/)):
- [des_crypto.hpp](./cpp/des_crypto.hpp)
- [des_crypto.cpp](./cpp/des_crypto.cpp)
- 测试:
- [test_crypto.cpp](./cpp/test_crypto.cpp)
- 只是 C++ 内部测试,想验证跨平台需要手动把 python 的密文拷贝到 [test_crypto.cpp](./cpp/test_crypto.cpp) 中替换验证
> 使用 VS2022 打开 [cpp.sln](./cpp/cpp.sln) 工程,默认就是已配置好 crypto++ 的依赖,若希望自行配置,可参考《[Visual Studio 搭建 Boost + CryptoPP 开发环境](https://exp-blog.com/lang/vs-da-jian-boostcryptopp-kai-fa-huan-jing/)》
### 0x22 python
- AES(依赖 [pycryptodome](https://pypi.org/project/pycryptodome/)):
- [aes_crypto.py](./python/aes_crypto.py)
- DES(依赖 [pyDes](https://pypi.org/project/pyDes/)):
- [des_crypto.py](./python/des_crypto.py)
- 测试: `cd python`
- 安装依赖: `python -m pip install -r requirements.txt`
- 执行命令: `python ./test/test_crypto.py`
- 只是 python 内部测试,想验证跨平台需要手动把 C++ 的密文拷贝到 [test_crypto.py](./python/test/test_crypto.py) 中替换验证
## 0x30 开发环境部署
python 环境直接安装就好, Windows 和 Mac 都是一样的。
主要说一下 C++ 的环境:
- Windows(需要提前安装 VS2022):
- GUI 方法: 使用 VS2022 打开 [cpp.sln](./cpp/cpp.sln) 文件即可
- CMD 方法:
1. `cd cpp`
2. 编译: `bin/build.ps1`
3. 执行: `bin/run.ps1`
- Mac/Linux (需要提前安装 g++ 和 cmake):
1. `cd cpp`
2. 编译: `bin/build.sh`
3. 执行: `bin/run.sh`
