vandalorumrex/crypt 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

vandalorumrex/crypt

最新稳定版本:v1.0.2

Composer 安装命令:

composer require vandalorumrex/crypt

包简介

Класс, который шифрует и расшифровывает файлы по алгоритмам, используемым WhatsApp

README 文档

README

Тестовые файлы можно найти в папке samples:

  • *.original - оригинальный файл;
  • *.key - ключ для шифрования (дешифрования) - mediaKey;
  • *.encrypted - зашифрованный файл;
  • *.sidecar - информация для стриминга.

Шифрование

  1. Generate your own mediaKey, which needs to be 32 bytes, or use an existing one when available.
  2. Expand it to 112 bytes using HKDF with SHA-256 and type-specific application info (see below). Call this value mediaKeyExpanded.
  3. Split mediaKeyExpanded into:
    • iv: mediaKeyExpanded[:16]
    • cipherKey: mediaKeyExpanded[16:48]
    • macKey: mediaKeyExpanded[48:80]
    • refKey: mediaKeyExpanded[80:] (not used)
  4. Encrypt the file with AES-CBC using cipherKey and iv, pad it and call it enc.
  5. Sign iv + enc with macKey using HMAC SHA-256 and store the first 10 bytes of the hash as mac.
  6. Append mac to the enc to obtain the result.

Дешифрование

  1. Obtain mediaKey.
  2. Expand it to 112 bytes using HKDF with SHA-256 and type-specific application info (see below). Call this value mediaKeyExpanded.
  3. Split mediaKeyExpanded into:
    • iv: mediaKeyExpanded[:16]
    • cipherKey: mediaKeyExpanded[16:48]
    • macKey: mediaKeyExpanded[48:80]
    • refKey: mediaKeyExpanded[80:] (not used)
  4. Obtain encrypted media data and split it into:
    • file: mediaData[:-10]
    • mac: mediaData[-10:]
  5. Validate media data with HMAC by signing iv + file with macKey using SHA-256. Take in mind that mac is truncated to 10 bytes, so you should compare only the first 10 bytes.
  6. Decrypt file with AES-CBC using cipherKey and iv, and unpad it to obtain the result.

Установка

composer require vandalorumrex/crypt

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-08-28