yekq / android_jni_aes_128_ecb_pkcs5padding Goto Github PK
View Code? Open in Web Editor NEW支持不定长数据的加解密,测试过与PHP的结果互通
支持不定长数据的加解密,测试过与PHP的结果互通
您好!
请问一下:
if (!HEX[lastChar] == out[index])
{
success == 0;
}
应该改成:
if (!(HEX[lastChar] == out[index]))
{
success == 0;
}
吧?
只要运行到 return out;这里,必然崩溃
stack corruption detected: aborted
libc: Fatal signal 11 (SIGSEGV) at 0xccf00121 (code=11021382), thread 13144
char base64_decode(const char data, int data_len) {
int ret_len = (data_len / 4) * 3;
int equal_count = 0;
char ret = NULL;
char f = NULL;
int tmp = 0;
int temp = 0;
char need[3];
int prepare = 0;
int i = 0;
if ((data + data_len - 1) == '=') {
equal_count += 1;
}
if ((data + data_len - 2) == '=') {
equal_count += 1;
}
if ((data + data_len - 3) == '=') {//seems impossible
equal_count += 1;
}
switch (equal_count) {
case 0:
ret_len += 4;//3 + 1 [1 for NULL]
break;
case 1:
ret_len += 4;//Ceil((63)/8)+1
break;
case 2:
ret_len += 3;//Ceil((62)/8)+1
break;
case 3:
ret_len += 2;//Ceil((61)/8)+1
break;
default:
break;
}
ret = (char *) malloc((size_t) ret_len);
if (ret == NULL) {
printf("No enough memory.\n");
exit(0);
}
memset(ret, 0, (size_t) ret_len);
f = ret;
while (tmp < (data_len - equal_count)) {
temp = 0;
prepare = 0;
memset(need, 0, 4);
while (temp < 4) {
if (tmp >= (data_len - equal_count)) {
break;
}
prepare = (prepare << 6) | (find_pos(data[tmp]));
temp++;
tmp++;
}
prepare = prepare << ((4 - temp) * 6);
for (i = 0; i < 3; i++) {
if (i == temp) {
break;
}
*f = (char) ((prepare >> ((2 - i) * 8)) & 0xFF);
f++;
}
}
*f = '\0';
size_t siz = strlen(ret);
char buf[siz];
memset(buf,0,siz);
sprintf(buf, "%s", ret);
char *out = (char *) malloc(siz);
memset(out,0,siz);
sprintf(out, "%s", buf);
printMsg(out);
// free(buf);
free(f);
return out;
}
for (i = 0; i < length; i += BLOCK_SIZE) {
BlockCopy(output, input);
state = (state_t *) output;
InvCipher();
XorWithIv(output);
Iv = input;
input += BLOCK_SIZE;
output += BLOCK_SIZE;
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.