簡介
- 此repository沒有使用任何外部crypt library實現AES加密算法,金鑰長度可接受128、192、256bits。
- 通過solar qube源碼掃描,security報警數=0。
- 明明有library,為甚麼要從頭開始寫呢?因為閒閒沒事做(X別人的library在做源碼掃描時總是很多問題跑出來,改別人300個問題不如從頭開始QQ。
注意事項
- 開發版本:python 3.9.1
- 外部引用:__future__、random、hashlib、base64
如何使用
1. 生成公鑰、私鑰對
載入Crypto module,此module包含加解密過程中所需的函式。
from AdvancedEncryptionStandard.Cipher import Crypto
使用AESkey的generate_key()方法產生金鑰、長度限定128、192、256。並且可以使用extract_key()將金鑰檔(.pem)儲存下來。
AES_key = Crypto.AESKey.generate_key(256)
with open('k1.pem', 'wb') as f:
f.write(AES_key.extract_key())
2. 資料加密
加密可接受的資料型態為bytes,若不是bytes可使用package中的converter針對不同資料型態來源進行轉換。
from DualRegev.IO import Converter
以下是加密的詳細流程:首先建立加密物件,接著使用import_key方法把金鑰讀取進來後,使用encrypt方法加密即可。
crypto_obj = Crypto.AESCrypto()
# 載入金鑰
with open('k1.pem', 'rb') as f:
key = f.read()
crypto_obj.import_key(key)
# 加密訊息
data = 'sddas'
data = data.encode()
cipher_text = crypto_obj.encrypt(data)
# 儲存密文
with open('cipher_text.bin', 'wb') as f:
f.write(cipher_text)
3. 資料解密
解密方法回傳的資料型態為bytes,使用AESCrypto中的方法decrypt即可進行解密。
# 創建加密工具物件
crypto_obj = Crypto.AESCrypto()
# 載入金鑰
with open('k1.pem', 'rb') as f:
key = f.read()
crypto_obj.import_key(key)
# 載入密文
with open('cipher_text.bin', 'rb') as f:
cipher_text = f.read()
# 解密訊息
data = crypto_obj.decrypt(cipher_text).decode()
print(data)
Metadata
Release files for AdvancedEncryptionStandard 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| advancedencryptionstandard-1.0.0.tar.gz | 8.3 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| AdvancedEncryptionStandard-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 18.9 kB
Release files / advancedencryptionstandard-1.0.0.tar.gz
| Download URL | advancedencryptionstandard-1.0.0.tar.gz |
|---|---|
| Size | 8.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6310b78ad6a9a4af31a252dfe11d692e57c094863c118dc6ac449be8c527234c
|
|
BLAKE2b-256 checksum How to use checksums |
4c5800651e00f192c201d5a0d91a925aca559040c88ada5cd758a870092759a1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.9.1
|
Release files / AdvancedEncryptionStandard-1.0.0-py3-none-any.whl
| Download URL | AdvancedEncryptionStandard-1.0.0-py3-none-any.whl |
|---|---|
| Size | 10.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9a790280d5152f813f3bf0f8012e761e2c41a7746ae684ed349282906a42b6a8
|
|
BLAKE2b-256 checksum How to use checksums |
2a769203cf6345e6aa333e8d9cfe166d19d47c112fcd7ae0ec985677acda1586
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.9.1
|
Security for AdvancedEncryptionStandard 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.