Тестовые файлы можно найти в папке 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
mediaKeyExpandedinto:iv:mediaKeyExpanded[:16]cipherKey:mediaKeyExpanded[16:48]macKey:mediaKeyExpanded[48:80]refKey:mediaKeyExpanded[80:](not used)
- Encrypt the file with AES-CBC using
cipherKeyandiv, pad it and call itenc. - Sign
iv + encwithmacKeyusing HMAC SHA-256 and store the first 10 bytes of the hash asmac. - Append
macto theencto 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
mediaKeyExpandedinto: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 + filewithmacKeyusing SHA-256. Take in mind thatmacis truncated to 10 bytes, so you should compare only the first 10 bytes. - Decrypt
filewith AES-CBC usingcipherKeyandiv, and unpad it to obtain the result.
composer require vandalorumrex/crypt