Closed ricox78 closed 6 years ago
The encrypted block has to be a multiple of 16, in your case being 17 bytes it adds 15 bytes of padding to make it 32 (16*2).
I'll look into a solution asap.
I could add 2 info: 1- If I use PKCS5Padding in Java, after 17 corrects bytes, 15 bytes @ 0xff are added at the byte array 2- the problem is present also when I send from qt to Java ... Thank’s again for all
Let me understand, AES says that the lenght of the block to decipher has to be a multiple of 16, you can handle the padding yourself by adding something to match this requirement or let the software do it (if you are using a string with termination char let the class handle it works well).
I don't use Java since a while, if you cipher the string in java, how many bytes in total you end up with? 32 or 17?
I try to explain better:
in Java I could init Chiper in this way:
m_encChiper = Cipher.getInstance("AES/CFB/NoPadding");
so no padding is managed and if I crypt something that out of the encrypt function result an array of 17 bytes, this is my result.
If I pass this array to java decrypt function I obtain the original String.
If I pass this array to your
encryption->decode(xMsg, hashKey, iv)
where xMsg is the 17 lenght byte array, I have my original string followed by 15bytes of non sense added as I indicated in the initial post.
So I could not find a way to manage padding in your library so I try to init my java Chiper to:
m_encChiper = Cipher.getInstance("AES/CFB/PKCS5PADDING");
I'm not sure CFB with padding have sense.. but I tried and when I decode in Qt the result is my original String followed bt 15 bytes all at 0x00ff.
I don't handle padding by myself, Java api did it for me .. but in NoPadding mode, the result of encrypt is not an array with a lenght multiple of 16 bytes. Is there a way to set your library to NoPadding?? Thank's again.
Can't you tell Java to use a zero-filled padding?
I think I can add PKCS5PADDING and other form of padding.
Thank's very much, very nice suggestion, initializing Chiper as following:
m_encChiper = Cipher.getInstance("AES/CFB/ZeroBytePadding");
java pad the coded string in the way in witch your library works! Thank's againg, probably padd management could be added to your wonderful work! Bye
Happy that it worked.
Please remember that my AES code is not audited or tested.
Yes for sure, I’ve used it to study a server simulator that works behind my app... first tests works, If can my experience with it contribute to test I’m happy..
I added PKCS7 and ISO padding, can you check them against Java?
I have an issue, I'm developing an android app that comunicate with a Qt develop application through an UDP socket.
Just to study, I tried to encrypt comunication using AES CFB NoPadding:
Java side:
Qt Side:
The problem is that, sending a string that encoded in java result in a 17 byte buffer, will be decoded in Qt correctly for the first 16 byte than QAESEncryption::decode at:
with i = 0 m_blocklen = 16, append other 16 bytes, the first is the correct 17th others 15 are non sense...
The same sended string has been encoded locally in Qt resulting in a 32 byte buffer that are corretly decoded. The same sended string has been encoded locally in Java resulting in a 17 byte buffer that are corretly decoded.
any idea on what's wrong when I pass from a platform to another??
Thanks a lot for all