Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

cipherflow

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Malicious code was recently detected in this package.

Affected versions:

0.1.00.1.10.1.3

cipherflow

纯 Python 对称加密库,零依赖。支持 AES/DES/3DES,ECB/CBC/CFB/OFB/CTR 模式。

pipPyPI
Version
0.1.3
Weekly downloads
0
Maintainers
1
Weekly downloads
 

cipherflow

纯 Python 对称加密库,零第三方依赖。

从零实现 AES(128/192/256)、DES、3DES 算法,支持 ECB / CBC / CFB / OFB / CTR 五种分组模式。

安装

pip install cipherflow

快速上手

import cipherflow as cf

# 生成密钥,加密
key = cf.generate_key("AES", 256)
ciphertext, iv = cf.encrypt("Hello World", key)

# 解密
plaintext = cf.decrypt(ciphertext, key, iv=iv)
print(plaintext.decode())  # Hello World

支持的算法与模式

算法密钥长度
AES128 / 192 / 256 bit
DES64 bit
3DES128 / 192 bit
模式需要 IV需要填充
ECB
CBC
CFB
OFB
CTR

API

核心函数

# 通用加密 / 解密
cf.encrypt(plaintext, key, algorithm="AES", mode="CBC", iv=None) -> (ciphertext, iv)
cf.decrypt(ciphertext, key, algorithm="AES", mode="CBC", iv=None) -> plaintext

# 算法快捷函数
cf.aes_encrypt(plaintext, key, mode="CBC", iv=None)
cf.aes_decrypt(ciphertext, key, mode="CBC", iv=None)
cf.des_encrypt(plaintext, key, mode="CBC", iv=None)
cf.des_decrypt(ciphertext, key, mode="CBC", iv=None)
cf.triple_des_encrypt(plaintext, key, mode="CBC", iv=None)
cf.triple_des_decrypt(ciphertext, key, mode="CBC", iv=None)

工具函数

# 生成随机密钥 / IV
cf.generate_key(algorithm="AES", bits=256) -> bytes
cf.generate_iv(algorithm="AES") -> bytes

# 打包(IV + 密文合并传输)
cf.pack(ciphertext, iv) -> bytes
cf.unpack(data) -> (ciphertext, iv)

示例:不同算法与模式

import cipherflow as cf

msg = "机密数据"

# AES-128-CTR
key = cf.generate_key("AES", 128)
ct, iv = cf.encrypt(msg, key, mode="CTR")
print(cf.decrypt(ct, key, mode="CTR", iv=iv).decode())

# DES-CBC
key = cf.generate_key("DES")
ct, iv = cf.des_encrypt(msg, key)
print(cf.des_decrypt(ct, key, iv=iv).decode())

# 3DES-ECB
key = cf.generate_key("3DES", 192)
ct, iv = cf.triple_des_encrypt(msg, key, mode="ECB")
print(cf.triple_des_decrypt(ct, key, mode="ECB").decode())

# pack / unpack 便于网络传输
ct, iv = cf.aes_encrypt(msg, cf.generate_key())
packed = cf.pack(ct, iv)
ct2, iv2 = cf.unpack(packed)

许可证

MIT

Keywords

encryption

FAQs

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts