🐛 Update decryption keys
This commit is contained in:
parent
3e9f4843f8
commit
dac2e9286c
2 changed files with 7 additions and 5 deletions
|
@ -1,6 +1,6 @@
|
|||
import updateKeys from './lib/updateKeys';
|
||||
|
||||
export default function decryptChunk(encryptedChunk: Buffer, [key0, key1, key2]: [number, number, number]): Buffer {
|
||||
export default function decryptChunk(encryptedChunk: Buffer, [key0, key1, key2]: [number, number, number]): {decryptedChunk: Buffer, keys: [number, number, number]} {
|
||||
const dv = new DataView(encryptedChunk.buffer);
|
||||
|
||||
const decryptedChunk = Buffer.alloc(encryptedChunk.length);
|
||||
|
@ -21,5 +21,5 @@ export default function decryptChunk(encryptedChunk: Buffer, [key0, key1, key2]:
|
|||
[key0, key1, key2] = updateKeys([key0, key1, key2], curChar);
|
||||
}
|
||||
|
||||
return decryptedChunk;
|
||||
return { decryptedChunk, keys: [key0, key1, key2] };
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import * as stream from 'stream';
|
||||
import decryptChunk from '../decryption/decryptChunk';
|
||||
|
||||
export default function decryptStream(inputStream: stream.Readable, decryptionKeys: [number, number, number]): stream.Readable {
|
||||
export default function decryptStream(inputStream: stream.Readable, [key0, key1, key2]: [number, number, number]): stream.Readable {
|
||||
let skippedRandomHeader = false;
|
||||
|
||||
const outStream = new stream.Readable({
|
||||
|
@ -9,7 +9,8 @@ export default function decryptStream(inputStream: stream.Readable, decryptionKe
|
|||
//There are 12 random bytes at the beginning, we need to use them to initialize the decryption keys, but we can ignore the decrypted bytes.
|
||||
if (!skippedRandomHeader) {
|
||||
const encryptedHeader: Buffer = inputStream.read(12);
|
||||
decryptChunk(encryptedHeader, decryptionKeys);
|
||||
const { keys } = decryptChunk(encryptedHeader, [key0, key1, key2]);
|
||||
[key0, key1, key2] = keys;
|
||||
skippedRandomHeader = true;
|
||||
}
|
||||
|
||||
|
@ -19,7 +20,8 @@ export default function decryptStream(inputStream: stream.Readable, decryptionKe
|
|||
//If end has been reached, stop
|
||||
this.push(null);
|
||||
} else {
|
||||
const decryptedChunk = decryptChunk(encryptedChunk, decryptionKeys);
|
||||
const { decryptedChunk, keys } = decryptChunk(encryptedChunk, [key0, key1, key2]);
|
||||
[key0, key1, key2] = keys;
|
||||
this.push(decryptedChunk);
|
||||
}
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue