ideawu / Objective-C-RSA

Doing RSA encryption and decryption with Objective-C on iOS
http://www.ideawu.com/blog/post/132.html
Other
1.15k stars 280 forks source link

并发时,SecItemCopyMatching方法会返回errSecItemNotFound #50

Open caocongcong opened 5 years ago

caocongcong commented 5 years ago

dispatch_queue_t queue = dispatch_queue_create("test", DISPATCH_QUEUE_CONCURRENT); for (int i = 0; i< 100; i++) { dispatch_async(queue, ^{ NSString test = [[params md5String] uppercaseString]; NSString test1 = [self p_publicKey]; NSString *test2 = [RSA encryptString:test publicKey:test1]; if (test2.length == 0) { NSLog(@"出错啦"); NSLog(@"md5===%@", test); NSLog(@"pubkey===%@", test1); NSLog(@"encrypted===%@", test2); } else { NSLog(@"任务ccc===%@", test2); } }); }

会有出现test2为空的情况

okocsis commented 5 years ago

@caocongcong are we supposed to google translate your text?

SnailLife commented 5 years ago

dispatch_queue_t queue = dispatch_queue_create("test", DISPATCH_QUEUE_CONCURRENT); for (int i = 0; i< 100; i++) { dispatch_async(queue, ^{ NSString test = [[params md5String] uppercaseString]; NSString test1 = [self p_publicKey]; NSString *test2 = [RSA encryptString:test publicKey:test1]; if (test2.length == 0) { NSLog(@"出错啦"); NSLog(@"md5===%@", test); NSLog(@"pubkey===%@", test1); NSLog(@"encrypted===%@", test2); } else { NSLog(@"任务ccc===%@", test2); } }); }

会有出现test2为空的情况

我也遇到了 请问你解决了吗

Tylor12 commented 4 years ago

我也遇见了,请问怎么解决.

ideawu commented 4 years ago

RSA 在这个地方使用了公共的资源: https://github.com/ideawu/Objective-C-RSA/blob/master/RSA.m#L131 所以不是线程安全的. 目前的解决方案是在你的代码中避免多线程调用 encryptString().

Tylor12 commented 4 years ago

RSA 在这个地方使用了公共的资源: https://github.com/ideawu/Objective-C-RSA/blob/master/RSA.m#L131 所以不是线程安全的. 目前的解决方案是在你的代码中避免多线程调用 encryptString().

本来RSA加解密比较耗时的,不放在多线程中,感觉不太好.