Objective-C-RSA icon indicating copy to clipboard operation
Objective-C-RSA copied to clipboard

并发时,SecItemCopyMatching方法会返回errSecItemNotFound

Open caocongcong opened this issue 6 years ago • 5 comments

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为空的情况

caocongcong avatar Dec 07 '18 09:12 caocongcong

@caocongcong are we supposed to google translate your text?

okocsis avatar Feb 04 '19 09:02 okocsis

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为空的情况

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

SnailLife avatar Jul 26 '19 11:07 SnailLife

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

Tylor12 avatar Feb 25 '20 09:02 Tylor12

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

ideawu avatar Feb 25 '20 11:02 ideawu

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

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

Tylor12 avatar Feb 26 '20 02:02 Tylor12