{"action":"created","issue":{"url":"https://api.github.com/repos/bricke/Qt-AES/issues/6","repository_url":"https://api.github.com/repos/bricke/Qt-AES","labels_url":"https://api.github.com/repos/bricke/Qt-AES/issues/6/labels{/name}","comments_url":"https://api.github.com/repos/bricke/Qt-AES/issues/6/comments","events_url":"https://api.github.com/repos/bricke/Qt-AES/issues/6/events","html_url":"https://github.com/bricke/Qt-AES/issues/6","id":307043507,"number":6,"title":"Qt-AES 256 CFB decode message from Java","user":{"login":"ricox78","id":37598565,"avatar_url":"https://avatars3.githubusercontent.com/u/37598565?v=4","gravatar_id":"","url":"https://api.github.com/users/ricox78","html_url":"https://github.com/ricox78","followers_url":"https://api.github.com/users/ricox78/followers","following_url":"https://api.github.com/users/ricox78/following{/other_user}","gists_url":"https://api.github.com/users/ricox78/gists{/gist_id}","starred_url":"https://api.github.com/users/ricox78/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ricox78/subscriptions","organizations_url":"https://api.github.com/users/ricox78/orgs","repos_url":"https://api.github.com/users/ricox78/repos","events_url":"https://api.github.com/users/ricox78/events{/privacy}","received_events_url":"https://api.github.com/users/ricox78/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2018-03-20T21:22:08Z","updated_at":"2018-03-21T21:36:17Z","closed_at":null,"author_association":"NONE","body":"I have an issue, I'm developing an android app that comunicate with a Qt develop application through an UDP socket.\r\n\r\nJust to study, I tried to encrypt comunication using AES CFB NoPadding:\r\n\r\nJava side:\r\n\r\n```\r\npublic final String key = \"123456789123\";\r\npublic final byte initVector[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05,             0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f};\r\nbyte [] hashKey = null;\r\nCipher m_encChiper;\r\nCipher m_decChiper;\r\n\r\n\r\n//Init \r\nMessageDigest digest = MessageDigest.getInstance(\"SHA-256\");\r\nhashKey = digest.digest(msgTools.key.getBytes(\"UTF-8\"));\r\n\r\nIvParameterSpec iv = new IvParameterSpec(msgTools.initVector);\r\nSecretKeySpec skeySpec = new SecretKeySpec(hashKey, \"AES\");\r\n\r\nm_encChiper = Cipher.getInstance(\"AES/CFB/NoPadding\");\r\nm_encChiper.init(Cipher.ENCRYPT_MODE, skeySpec, iv);\r\n\r\nm_decChiper = Cipher.getInstance(\"AES/CFB/NoPadding\");\r\nm_decChiper.init(Cipher.DECRYPT_MODE, skeySpec, iv);\r\n\r\n//Enc and Dec function\r\n\r\n   public byte[] encrypt(String value) {\r\n        try {\r\n\r\n            byte[] encrypted = m_encChiper.doFinal(value.getBytes());\r\n            return encrypted;\r\n        } catch (Exception ex) {\r\n            ex.printStackTrace();\r\n        }\r\n        return null;\r\n    }\r\n\r\n    public String decrypt(byte [] encrypted) {\r\n        try {\r\n\r\n            byte[] original = m_decChiper.doFinal(encrypted);\r\n\r\n            return new String(original);\r\n        } catch (Exception ex) {\r\n            ex.printStackTrace();\r\n        }\r\n        return null;\r\n    }\r\n```\r\n\r\nQt Side:\r\n\r\n```\r\nQAESEncryption *encryption = NULL;\r\nQString key = \"123456789123\";\r\nQByteArray hashKey = QCryptographicHash::hash(key.toLocal8Bit(),             QCryptographicHash::Sha256);\r\nQByteArray iv;\r\n\r\nencryption = new QAESEncryption(QAESEncryption::AES_256,     QAESEncryption::CFB);\r\nquint8 iv_16[16]     = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f};\r\n    for (int i=0; i<16; i++)\r\n        iv.append(iv_16[i]);\r\n\r\n\r\nQByteArray SenderThread::encryptData(QString msg)\r\n{\r\n    return encryption->encode(msg.toLocal8Bit(), hashKey, iv);\r\n}\r\n\r\nQString SenderThread::decodeData(QByteArray xMsg)\r\n{\r\n    return QString(encryption->decode(xMsg, hashKey, iv));\r\n}\r\n```\r\nThe 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:\r\n```\r\n...\r\ncase CFB:\r\n            if (i+m_blocklen < rawText.size()){\r\n                ret.append(byteXor(rawText.mid(i+m_blocklen, m_blocklen),\r\n                                   cipher(expandedKey, rawText.mid(i, m_blocklen))));\r\n...\r\n```\r\n\r\nwith i = 0 m_blocklen = 16, append other 16 bytes, the first is the correct 17th others 15 are non sense...\r\n\r\nThe same sended string has been encoded locally in Qt resulting in a 32 byte buffer that are corretly decoded.\r\nThe same sended string has been encoded locally in Java resulting in a 17 byte buffer that are corretly decoded.\r\n\r\nany idea on what's wrong when I pass from a platform to another??\r\n\r\nThanks a lot for all\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/bricke/Qt-AES/issues/comments/375104069","html_url":"https://github.com/bricke/Qt-AES/issues/6#issuecomment-375104069","issue_url":"https://api.github.com/repos/bricke/Qt-AES/issues/6","id":375104069,"user":{"login":"ricox78","id":37598565,"avatar_url":"https://avatars3.githubusercontent.com/u/37598565?v=4","gravatar_id":"","url":"https://api.github.com/users/ricox78","html_url":"https://github.com/ricox78","followers_url":"https://api.github.com/users/ricox78/followers","following_url":"https://api.github.com/users/ricox78/following{/other_user}","gists_url":"https://api.github.com/users/ricox78/gists{/gist_id}","starred_url":"https://api.github.com/users/ricox78/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ricox78/subscriptions","organizations_url":"https://api.github.com/users/ricox78/orgs","repos_url":"https://api.github.com/users/ricox78/repos","events_url":"https://api.github.com/users/ricox78/events{/privacy}","received_events_url":"https://api.github.com/users/ricox78/received_events","type":"User","site_admin":false},"created_at":"2018-03-21T21:36:17Z","updated_at":"2018-03-21T21:36:17Z","author_association":"NONE","body":"Thank's very much, very nice suggestion,\r\ninitializing Chiper as following:\r\n\r\n`m_encChiper = Cipher.getInstance(\"AES/CFB/ZeroBytePadding\");`\r\n\r\njava pad the coded string in the way in witch your library works!\r\nThank's againg, probably padd management could be added to your wonderful work!\r\nBye"}}
{"actor":{"display_login":"ricox78"}}