阅读源码的时候发现了几个问题,提几个修改建议。
larry19840909 opened this issue · comments
非常感谢作者的代码。
我在阅读和使用的过程中发现了三个问题,我自己是这样修改的,不知道对作者原先意图是否有误解。
-
内存泄露的问题
在JNIEncrypt.c中,encode和decode函数在返回jsting之前没有将base64,以及getkey产生的内存产生的临时内存free掉。 -
加密填充
这段代码是多余的
if(inLength<16) { paddingInput=(uint8_t*)malloc(16); paddingInputLengt=16; int i; for (i = 0; i < 16; i++) { if (i < inLength) { paddingInput[i] = in[i]; } else { paddingInput[i] = HEX[16 - inLength]; } }
在inLength < 16的时候
size其实就是等于16的,所以这段逻辑和else里的是一样的,可以去除 -
解密去除填充
在findPaddingIndex这个函数里。
原来去除后缀的方式是从头往前查,而且是双重循环,感觉有点耗。
既然在padding的时候,填充的是dif,所以不需要再判断'\n'之类的。
直接取解密后的字符串最后一位即可。
return (int)(strlen(str) - str[strlen(str) - 1]);
当然了,我不知道是不是有特殊的例子存在。
thax for your suggestion.
- already fix the bug lastday. look this pull25
2.3. could u give me a pull request?
thanx a lot again.
抱歉,我不太会用git,我把我修改的代码贴到这里来。
okay,dont past to this issue, u can past to the website : https://pastebin.com/
and give a url.
thanx.
2和3修改的就是下面两个函数。
aes.c中AES_128_ECB_PKCS5Padding_Encrypt函数的修改
https://pastebin.com/AJJWguwS
aes.c中findPaddingIndex函数的修改
https://pastebin.com/PBpsXNKd
okay, thanx a lot again.
i will add your github address to the readme file in this library. thanx for your comment.
already added u homepage to readme. thanx a lot.
commic:c6e7886b4b68004c41b3bca2dfa9b0f476c2d505
i need close the issue.