Implicit declaration of function 'js_private_decrypt' is invalid in C99

KralLee 2014-07-29 07:18:12

Implicit declaration of function 'js_private_decrypt' is invalid in C99


就是这么一个问题...在64位下就会出现这个问题。不是64位就可以了。
解决方法也看了很多
1、修改target->C Language Dialect 这个方法不行。
2、是不是有什么c的库没有添加上,具体也不知道要添加什么库。
错误代码
char *plainText = js_private_decrypt([cipher UTF8String], [privateKeyPath UTF8String]);

当然,js_private_decrypt,这个方法也得贴出来。
char *js_private_decrypt(const char *cipher_text, const char *private_key_path) {
RSA *rsa_privateKey = NULL;
FILE *fp_privateKey;
int rsa_private_len;

if ((fp_privateKey = fopen(private_key_path, "r")) == NULL) {
printf("Could not open %s\n", private_key_path);
return '\0';
}

if ((rsa_privateKey = PEM_read_RSAPrivateKey(fp_privateKey, NULL, NULL, NULL)) == NULL) {
printf("Error loading RSA Private Key File.");
return '\0';
}
fclose(fp_privateKey);

printf("Cipher text: %s\n", cipher_text);

rsa_private_len = RSA_size(rsa_privateKey);
printf("RSA private length: %d\n", rsa_private_len);

size_t crypt_len = 0;

unsigned char *crypt = base64_decode(cipher_text, strlen(cipher_text), &crypt_len);

printf("Decoded cipher: %s\nCrypt length: %ld\n", crypt, crypt_len);

// If no static, it will cause "address of stack memory associated with local variable ...", which mean the variable will released from memory after the end of this function
char *plain_char = malloc(crypt_len);
// initialize
strcpy(plain_char, "");

char *err = NULL;
for (int i = 0; i < crypt_len; i += rsa_private_len) {
unsigned char *crypt_chunk = malloc(rsa_private_len + 1);
memcpy(&crypt_chunk[0], &crypt[i], rsa_private_len);

printf("Crypt chunk: %s\n", crypt_chunk);

unsigned char *result_chunk = malloc(crypt_len + 1);
int result_length = RSA_private_decrypt(rsa_private_len, crypt_chunk, result_chunk, rsa_privateKey, RSA_PKCS1_PADDING);
// chunk length should be the size of privatekey (in bytes) minus 11 (overhead during encryption)
printf("Result chunk: %s\nChunk length: %d\n", result_chunk, result_length);

// this is to omit the dummy character behind
// i.e. Result chunk: ABC-1234567-201308101427371250-abcdefghijklmnopqrstuv\240Z
// Chunk length: 53
// New chunk: ABC-1234567-201308101427371250-abcdefghijklmnopqrstuv
//
// by copying the chunk to a temporary variable with an extra length (i.e. in this case is 54)
// and then set the last character of temporary variable to NULL
char tmp_result[result_length + 1];
memcpy(tmp_result, result_chunk, result_length);
tmp_result[result_length] = '\0';
printf("New chunk: %s\n", tmp_result);

if (result_length == -1) {
ERR_load_CRYPTO_strings();
fprintf(stderr, "Error %s\n", ERR_error_string(ERR_get_error(), err));
fprintf(stderr, "Error %s\n", err);
}

strcat(plain_char, tmp_result);
}

RSA_free(rsa_privateKey);
printf("Final result: %s\n", plain_char);

return plain_char;
}


...全文
1571 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
xj309508871 2014-11-07
  • 打赏
  • 举报
回复
已经解决这个问题了,报错原因是找不到这个函数,在文件中 引入 函数所在的头文件 即可 #import <objc/runtime.h>
xj309508871 2014-11-07
  • 打赏
  • 举报
回复
我也遇到了这个问题: 64位编译就报错,32位正常运行。 Implicit declaration of function 'class_getProperty' is invalid in C99.
if (class_getProperty([aViewController class], "block"))
    {
        // it has that property!
        [aViewController setBlock:block];
    }
KralLee 2014-07-30
  • 打赏
  • 举报
回复
引用 1 楼 zhangao0086 的回复:
你是不是在申明js_private_decrypt这个方法之前就使用了这个方法?
不会啊,声明和使用都不在一个类中的。 这个不应该是编码的问题,因为我的非64位都可以运行的。
Bannings 2014-07-29
  • 打赏
  • 举报
回复
你是不是在申明js_private_decrypt这个方法之前就使用了这个方法?

29,027

社区成员

发帖
与我相关
我的任务
社区描述
主要讨论与iOS相关的软件和技术
社区管理员
  • iOS
  • 大熊猫侯佩
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧