Skip to content

IllegalBlockSizeException when decrypt 2 #3

@lepicekmichal

Description

@lepicekmichal

I don't know if it was the same problem as in #1 but the bug is in the actual code.

this line
it.write(encryptedBytes.size)
assumes that encrypted data are smaller than 256 which is quite limiting. Outputstream in fact cannot write bigger int then 1 byte, 8 bits. Kotlin Int, however, has 4 bytes, 32 bits.

Analogically, the decryption has the same bug.

I fixed the code with following lines:

for (i in 0..24 step 8) {
    it.write(encryptedBytes.size shr i)
}

and

val encryptedBytesSize = List(4) { it * 8 }.fold(0) { acc, i -> acc + (it.read() and 0xff shl i) }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions