encryption - Decrypt Mega.co.nz file partially using aes 128 ctr for streaming range support -



encryption - Decrypt Mega.co.nz file partially using aes 128 ctr for streaming range support -

how decrypt aes 128 ctr encrypted file middle http range support? here encrypted file: https://www.dropbox.com/s/8e9qembud6n3z7i/encrypted.txt?dl=0

the key base64 encrypted: e7vqwj3cv1jui5pklirtdq9srjt1dhiqygzpspiivp0

mega docs: https://mega.co.nz/#doc

the iv calculated decrypting key gives array:

array ( [0] => 330649690 [1] => 1037877074 [2] => 1418435172 [3] => 2519395597 [4] => 257049755 [5] => 1963858090 [6] => 1645006666 [7] => 2451723517 )

the iv obtained slicing array @ 4th offset length of 2 , lastly 2 elements of array filled 0:

array ( [0] => 257049755 [1] => 1963858090 [2] => 0 [3] => 0 )

then key xor'd , made 128bit array converted string php function pack:

$key = array($key[0] ^ $key[4], $key[1] ^ $key[5], $key[2] ^ $key[6], $key[3] ^ $key[7]); $key = base64_encode(a32_to_str($key)); $iv = base64_encode(a32_to_str($iv));

then file decrypted using normal php aes library. using mcrypt_generic decryption process. problem arises when seek decrypt file 2nd byte or 3rd or middle. works fine if decrypt 1st byte.

another thing have noticed is, if decrypt file 2nd byte, before that, decrypt random string or digit 0, decryption works 2nd byte then. suppose has iv block counter. decrypt random byte go on decrypting actual cipher works. need start decrypting file start, lets 40mb offset back upwards live strem seeking. consume much memory because have decrypt 40mb of 0's before seeking can done. how can move iv counter value 40mb offset ??

i read iv increased +1 each block decryption. since iv array have tried not work if add together 1 in it. i've been @ months no fruit. please help

here previous question helped understanding process bit: aes 128 bit ctr partial file decryption php

your initial research indeed correct. in ctr mode, iv (or nonce) incremented 1 after each encryption operation. (encryption , decryption same operation in ctr mode, can substitute 1 word other necessary.)

in other words, state of ctr mode cipher can predicted in advance – add together number of blocks encrypted initial iv. in particular, state not depend on plaintext in way. aes has block size of 16, add together number of bytes encrypted divided 16.

the iv can considered 128-bit integer stored in big endian. cryptography api utilize represents array of 4 32-bit integers. add together number of blocks 4th integer before initializing cipher. if think you'll need handle more 4 billion blocks or so, need add together handling overflow 3rd integer.

the trickier part initializing cipher state have encrypted number of bytes not divisible block size. solution first initialize cipher number of bytes encrypted divided 16, rounded down, , encrypting (the number of bytes encrypted mod 16) dummy bytes. believe in fact suspected.

you're writing in php, i'm posting method mega downloader programme i've written in java in case helps:

class="lang-java prettyprint-override">public cipher getdownloadcipher(final long startposition) throws exception { final cipher cipher = cipher.getinstance("aes/ctr/nopadding"); final bytebuffer buffer = bytebuffer.allocate(16).put(nonce); buffer.aslongbuffer().put(startposition / 16); cipher.init(cipher.decrypt_mode, new secretkeyspec(key, "aes"), new ivparameterspec(buffer.array())); final int skip = (int) (startposition % 16); if (skip != 0) { if (cipher.update(new byte[skip]).length != skip) { //that should work ctr mode cipher throw new ioexception("failed skip bytes cipher"); } } homecoming cipher; }

encryption cryptography streaming aes playready

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -