Skip to content

PriKit is a privacy-first productivity toolkit designed to provide secure, efficient workflow solutions while ensuring complete data control. We believe productivity should never come at the cost of privacy. PriKit 是一个专注于隐私保护的生产力工具集合,旨在为用户提供安全、高效的工作流解决方案,同时确保数据的完全掌控权。我们相信生产力不应以牺牲隐私为代价。

Notifications You must be signed in to change notification settings

Cryptocxf/PriKit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PriKit SDK (文件脱敏SDK)

基于Presidio的多格式文件脱敏SDK,支持PDF、Word、Excel、图片、PPT文件的敏感信息脱敏处理。

  • 支持脱敏数据类别:
字段 解释
PERSON 姓名
LOCATION 地理位置
EMAIL_ADDRESS 电子邮件地址
ID 身份证号
IP_ADDRESS IP地址(IPv4或IPv6)
URL 网址
DATE_TIME 日期时间信息
NRP 国籍、宗教或政治团体
PHONE_NUMBER 电话号码
CREDIT_CARD 信用卡号码(12-19位数字)
CRYPTO 加密货币钱包地址
IBAN_CODE 国际银行账户号码

1. 功能特性

  • 多格式支持:PDF、Word、Excel、图片(JPG/PNG等)、PPT
  • 多种脱敏方法:颜色填充、字符替换、打码、伪造数据、加密
  • 中文优化:专门优化的中文敏感信息识别(姓名、手机号、身份证号等)
  • 多种使用方式:命令行、Python SDK、API调用
  • 格式保留:Word/Excel/PPT脱敏后完整保留原始格式
  • 批量处理:支持单文件和批量文件脱敏
  • 任务管理:完整的任务状态跟踪和进度监控

2. 安装

# 1. 克隆仓库
git clone https://github.com/Cryptocxf/PriKit.git
cd PriKit

# 2. 安装依赖
pip install -r requirements.txt

# 3. 安装中文NLP模型
python -m spacy download zh_core_web_trf

# 或者直接用已下载的zh_core_web_trfxxxx.whl安装
pip install zh_core_web_trf-xxxx.whl

# 4. 安装Tesseract OCR来识别图片中文字
yum install -y tesseract tesseract-langpack-chi_sim

# 5. 安装SDK(开发模式)
pip install -e .
# 完成

3. 快速开始

方式一:命令行使用

# PDF脱敏
prikit pdf document.pdf --method color --color white

# Word脱敏
prikit word document.docx --method mask

# Excel脱敏
prikit excel data.xlsx --method encrypt --key 123456

# 图片脱敏
prikit image photo.jpg --method char --char "*"

# PPT脱敏(默认只有mask,不用method参数)
prikit ppt presentation.pptx

# 启动API服务器
prikit api --host 0.0.0.0 --port 5000

方式二:python代码中使用

from prikit import PDFAnonymizer

# 创建脱敏器
anonymizer = PDFAnonymizer(language='zh', verbose=True)

# 单文件脱敏
result = anonymizer.anonymize(
    "input.pdf",
    method="color",
    color="white"
)
print(f"脱敏完成: {result}")

# 批量脱敏
files = ["file1.pdf", "file2.pdf"]
results = anonymizer.anonymize_batch(
    files,
    method="char",
    char="*"
)

方式三:API调用

# 单文件脱敏
curl -X POST http://localhost:5000/api/anonymize/single \
  -H "Content-Type: application/json" \
  -d '{
    "file_path": "test.pdf",
    "file_type": "pdf",
    "method": "mask",
    "language": "zh"
  }'

# 文件上传脱敏
curl -X POST http://localhost:5000/api/upload/single \
  -F "file=@document.pdf" \
  -F "file_type=pdf" \
  -F "method=mask"

# 查询任务状态
curl http://localhost:5000/api/task/{task_id}

# 下载结果文件
curl http://localhost:5000/api/download/{task_id}/0 -o result.pdf

4. 支持文件类型和方法

文件类型 支持格式 支持方法 特殊参数
PDF .pdf mask, color, char --color可选white, black, red, blue;
--char可任意自定义字符。
Image .jpg, .jpeg, .png, .bmp, .tiff mask, color, char --color可选white, black, red, blue;
--char可任意自定义字符。
Word .docx, .doc fake, mask, encrypt --key,仅当method = encrypt需要,仅支持6位数字
Excel .xlsx, .xls fake, mask, encrypt --key,仅当method = encrypt需要,仅支持6位数字
PPT .pptx, .ppt mask 仅支持mask脱敏,用*代替

5. 配置参数

通用参数

  • language:语言(zh/en)
  • verbose:详细输出模式
  • output_dir:输出目录(默认:./anonymized-datas

特定参数

  • color:填充颜色(white/black/red/blue
  • char:替换任意字符
  • encrypt:6位数字密钥

6. Docker部署

# 构建镜像
docker build -t anonymization-sdk .

# 运行容器
docker run -p 5000:5000 \
  -v ./data:/app/data \
  anonymization-sdk

7. 示例代码

更多使用示例请查看 examples/ 目录:

  • basic_usage.py - 基础使用示例

  • batch_processing.py - 批量处理示例

  • api_server.py - API服务器示例

8. 安全性

  • 所有上传文件存储在临时目录,处理完成后自动清理

  • 支持加密脱敏,使用AES-256加密算法

  • 任务状态信息存储在内存中,可配置持久化存储

  • 支持文件大小限制和类型验证

About

PriKit is a privacy-first productivity toolkit designed to provide secure, efficient workflow solutions while ensuring complete data control. We believe productivity should never come at the cost of privacy. PriKit 是一个专注于隐私保护的生产力工具集合,旨在为用户提供安全、高效的工作流解决方案,同时确保数据的完全掌控权。我们相信生产力不应以牺牲隐私为代价。

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages