我使用 openssl rsa 函数来解密密文,一些代码是这样的:
+ (NSString *)RsaDecryptWithPrivateKey:(NSString *)encryptedString {
void *encrypt = NULL; // Encrypted message
char *decrypt = NULL; // Decrypted message
char *err = NULL; // Buffer for any error messages
BIO *bio = BIO_new_mem_buf((char *)prikey, -1);
RSA *prikey = PEM_read_bio_RSAPrivateKey(bio, NULL, NULL, NULL);
encrypt = malloc(RSA_size(prikey));
NSData *encryptedData = [NSData dataFromBase64String:encryptedString];
int encryptedData_length = (int)[encryptedData length];
encrypt = (void *)[encryptedData bytes];
decrypt = malloc(encryptedData_length);
memset(decrypt, 0, encryptedData_length);
if(RSA_private_decrypt(encryptedData_length,
(unsigned char*)encrypt,
(unsigned char*)decrypt,
prikey, RSA_PKCS1_OAEP_PADDING) == -1) {
ERR_load_crypto_strings();
ERR_error_string(ERR_get_error(), err);
goto free_stuff;
}
return [[NSString alloc] initWithBytes:decrypt length:strlen(decrypt) encoding:NSUTF8StringEncoding];
free_stuff:
RSA_free(prikey);
free(encrypt);
free(decrypt);
free(err);
}
它工作正常。但是,当我使用 Instrument 跟踪有关它的泄漏时,会出现一些警告,如下所示:
我不知道如何解决这个问题,你能给我一些建议吗?