vandalorumrex / crypt
Класс, который шифрует и расшифровывает файлы по алгоритмам, используемым WhatsApp
v1.0
2025-08-28 17:47 UTC
Requires
- php: >=8.1
- cakephp/cakephp: 5.2.*
- cakephp/migrations: ^4.0.0
- cakephp/plugin-installer: ^2.0
Requires (Dev)
- cakephp/bake: ^3.0.0
- cakephp/cakephp-codesniffer: ^5.0
- cakephp/debug_kit: ^5.0.0
- josegonzalez/dotenv: ^4.0
- phpunit/phpunit: ^10.5.5 || ^11.1.3 || ^12.1
Suggests
- cakephp/repl: Console tools for a REPL interface for CakePHP applications.
- dereuromark/cakephp-ide-helper: After baking your code, this keeps your annotations in sync with the code evolving from there on for maximum IDE and PHPStan/Psalm compatibility.
- markstory/asset_compress: An asset compression plugin which provides file concatenation and a flexible filter system for preprocessing and minification.
- phpstan/phpstan: PHPStan focuses on finding errors in your code without actually running it. It catches whole classes of bugs even before you write tests for the code.
This package is auto-updated.
Last update: 2025-08-28 18:46:40 UTC
README
Тестовые файлы можно найти в папке samples
:
*.original
- оригинальный файл;*.key
- ключ для шифрования (дешифрования) -mediaKey
;*.encrypted
- зашифрованный файл;*.sidecar
- информация для стриминга.
В качестве задания со звёздочкой можно реализовать генерацию информации для стриминга. Эта генерация не должна делать дополнительных чтений из потока-исходника.
Шифрование
- Generate your own
mediaKey
, which needs to be 32 bytes, or use an existing one when available. - Expand it to 112 bytes using HKDF with SHA-256 and type-specific application info (see below). Call this value
mediaKeyExpanded
. - Split
mediaKeyExpanded
into:iv
:mediaKeyExpanded[:16]
cipherKey
:mediaKeyExpanded[16:48]
macKey
:mediaKeyExpanded[48:80]
refKey
:mediaKeyExpanded[80:]
(not used)
- Encrypt the file with AES-CBC using
cipherKey
andiv
, pad it and call itenc
. - Sign
iv + enc
withmacKey
using HMAC SHA-256 and store the first 10 bytes of the hash asmac
. - Append
mac
to theenc
to obtain the result.
Дешифрование
- Obtain
mediaKey
. - Expand it to 112 bytes using HKDF with SHA-256 and type-specific application info (see below). Call this value
mediaKeyExpanded
. - Split
mediaKeyExpanded
into:iv
:mediaKeyExpanded[:16]
cipherKey
:mediaKeyExpanded[16:48]
macKey
:mediaKeyExpanded[48:80]
refKey
:mediaKeyExpanded[80:]
(not used)
- Obtain encrypted media data and split it into:
file
:mediaData[:-10]
mac
:mediaData[-10:]
- Validate media data with HMAC by signing
iv + file
withmacKey
using SHA-256. Take in mind thatmac
is truncated to 10 bytes, so you should compare only the first 10 bytes. - Decrypt
file
with AES-CBC usingcipherKey
andiv
, and unpad it to obtain the result.