otpfile
使用一次性密码本存储重要文件.
对于一些重要文件或者密钥, 可以使用物理介质比如纸或者单独的存储器去保存, 这些需要维护的介质可能会遇到丢失或者损坏的风险.
为了避免物理介质维护不当的风险, 存储在云存储中是个好办法, 不过存储在云存储中, 文件可能会被分析或者泄露, 所以为了安全使用云存储记录重要文件, 可以设计一套加密文件方案, 使得:
- 加密后的文件有多份
- 单独的文件只是解密的一部分参数
- 不需要为此维护密码
实现这个方案需要使用One-time pad, 构建多个与原文等长的密码本, 然后将密文结果和各个密码本分散存储, 使得任何单独的泄露事件对数据无影响.
例如一种方案是产生密文文件和1个密码本文件, 然后将这两个文件复制为四个. 分别保存在 GoogleDrive, OneDrive, Dropbox, 百度云, 使得每一家平台不会造成泄露风险并且进行冗余保存.
文件结构
File Description:
涉及到的签名和哈希均为SHA256
整体结构:
+--------+------------+-------------+--------+----+-------------+------------+----------------+
|OTP1(4B)|groupID(64B)|fileHash(32B)|size(4B)|name|fileCount(4B)|segCount(4B)|seg[1..segCount]|
+--------+------------+-------------+--------+----+-------------+------------+----------------+
首部的前四个字节标识类型与版本
groupID: 对于所有加密过的文件的统一标识
fileHash: 原文件的签名信息, 用于还原时校验解密数据
name: 被加密文件的名称, 用于还原时创建文件
fileCount: 需要创建多少个文件, 至少为2(密文文件+1个密码本文件)
segCount: 文件包含的段数量, 每个段可以承载不超过128KB的密文或者密码本
对于每个段:
+---------------------------+--------+----+--------+-----+--------------+
|signatures(fileCount * 32B)|size(4B)|body|size(4B)|nonce|signature(32B)|
+---------------------------+--------+----+--------+-----+--------------+
signatures: 所有文件中这个位置的段, 其数据的签名汇总, 用于校验所有文件的这一批段数据是否缺失或者异常
signature: 该段的在此文件的签名, hash(groupID + body + nonce)
用法
from otpfile import OTP
o = OTP()
files: list[str] = o.encrypt_file('/path/to/secret.data', '/path/to/write/output/folder')
o.decrypt_file(files, '/path/to/write/recover/folder')
Metadata
Release files for otpfile 0.1.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 | |
|---|---|---|---|---|
| otpfile-0.1.0.tar.gz | 6.7 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| otpfile-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 13.8 kB
Release files / otpfile-0.1.0.tar.gz
| Download URL | otpfile-0.1.0.tar.gz |
|---|---|
| Size | 6.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9a89e2138ff26422b1601646b2dea3891c05ddc2328cc06232b1acd491d4c0fc
|
|
BLAKE2b-256 checksum How to use checksums |
8d4c0d6e28ed4c0c6c0962283b3262fca90ffbb11553ddbfa5bc343c149553bf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.0
|
Release files / otpfile-0.1.0-py3-none-any.whl
| Download URL | otpfile-0.1.0-py3-none-any.whl |
|---|---|
| Size | 7.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
929623175dc16a4ffc8dd69279035e94a7d1c44904321ebe0a2dccc6a702ad7d
|
|
BLAKE2b-256 checksum How to use checksums |
49cfb91ac0a6f9c8848a406128534b450d8368c8fb32614952f4e1d337cf2340
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.0
|
Security for otpfile 0.1.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.
To learn more about protecting yourself from malicious actors, visit our package security documentation.