Coder Social home page Coder Social logo

android_jni_aes_128_ecb_pkcs5padding's People

Contributors

yekq avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

android_jni_aes_128_ecb_pkcs5padding's Issues

解码部分Base64崩溃

只要运行到 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((6
3)/8)+1
break;
case 2:
ret_len += 3;//Ceil((62)/8)+1
break;
case 3:
ret_len += 2;//Ceil((6
1)/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;
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.