{"action":"created","issue":{"url":"https://api.github.com/repos/hohl/MIHCrypto/issues/29","labels_url":"https://api.github.com/repos/hohl/MIHCrypto/issues/29/labels{/name}","comments_url":"https://api.github.com/repos/hohl/MIHCrypto/issues/29/comments","events_url":"https://api.github.com/repos/hohl/MIHCrypto/issues/29/events","html_url":"https://github.com/hohl/MIHCrypto/issues/29","id":88544874,"number":29,"title":"Question: RSA key in blocks","user":{"login":"scastro","id":497882,"avatar_url":"https://avatars.githubusercontent.com/u/497882?v=3","gravatar_id":"","url":"https://api.github.com/users/scastro","html_url":"https://github.com/scastro","followers_url":"https://api.github.com/users/scastro/followers","following_url":"https://api.github.com/users/scastro/following{/other_user}","gists_url":"https://api.github.com/users/scastro/gists{/gist_id}","starred_url":"https://api.github.com/users/scastro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scastro/subscriptions","organizations_url":"https://api.github.com/users/scastro/orgs","repos_url":"https://api.github.com/users/scastro/repos","events_url":"https://api.github.com/users/scastro/events{/privacy}","received_events_url":"https://api.github.com/users/scastro/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-06-15T21:25:03Z","updated_at":"2015-06-16T06:08:27Z","closed_at":null,"body":"Hi,\r\n\r\nI have to exchange keys with the server (in JAVA using bouncycastle) and my iOS app. So the server has the key size issue and send me the key in blocks (each one encrypted with my public key). The problem is that when I want to decrypt one of these blocks I get the error \r\n\r\n \"Size of data to encrypt must not exceed size of RSA key. ....\"\r\n\r\nBut I don't really understand why because each block is smaller that the size of my key. Here is my code:\r\n\r\n    MIHRSAKeyFactory* factory = [[MIHRSAKeyFactory alloc] init];\r\n    factory.preferedKeySize = MIHRSAKey1024;\r\n    MIHKeyPair *keyPair = [factory generateKeyPair];\r\n    clientPrivateKey = keyPair.private;\r\n    clientPublicKey = keyPair.public;\r\n    ...\r\n    [self postOperation:@\"exchangekey\" params:params onCompletion:^(NSDictionary *json)\r\n     {\r\n         NSError *error = nil;\r\n         NSString* dataStr = [[[json objectForKey:@\"chains\"] objectAtIndex:0] objectForKey:@\"chain\"];\r\n         NSData* data2 = [dataStr dataUsingEncoding:NSUTF8StringEncoding];\r\n         [self log:[NSString stringWithFormat:@\"Server response (%ld): %@\",data2.length,data2]];\r\n         //NSData* data = [NSData dataWithData:[[[json objectForKey:@\"chains\"] objectAtIndex:0] objectForKey:@\"chain\"]];\r\n         [clientPrivateKey decrypt:data2 error:&error];\r\n         [self log:[NSString stringWithFormat:@\"Decript error: %@\",error.description]];\r\n     }];\r\n\r\nAnd the log shows this\r\n\r\nServer response (256): <37653734 38363964 65386134 36663930 66656530 35356230 65393937 64626432 66343032 65333061 35373437 62626361 34316133 61643262 39373037 36353230 65343765 66656266 33666433 63323537 62303634 39613461 30613034 37666161 32303862 34313331 30353239 30323163 35303966 39333833 30383332 64366662 65323433 33623862 33326532 61616330 62613239 63653161 33356230 39373831 65316430 33373961 33623838 30633532 37393732 39663235 63363332 34653732 32333031 64326662 35366264 33633835 61323533 37363235 35613836 30613863 65396533 33633835 61363330 35666333 33386263 63383962 30636632 30336535>\r\nDecript error: Error Domain=MIHOpenSSLErrorDomain Code=67522668 \"Size of data to encrypt must not exceed size of RSA key. If you want to securly encrypt large blocks of data combine RSA with AES. (See https://github.com/hohl/MIHCrypto/issues/24 for more details about that topic.)\" UserInfo=0x7fb4edb8f390 {NSLocalizedDescription=Size of data to encrypt must not exceed size of RSA key. If you want to securly encrypt large blocks of data combine RSA with AES. (See https://github.com/hohl/MIHCrypto/issues/24 for more details about that topic.)}\r\n\r\nAny ideas on what I'm doing wrong?\r\n\r\nIs my first try with this lib and this kind of encryption so apologies in advance if this is a simple newbie error."},"comment":{"url":"https://api.github.com/repos/hohl/MIHCrypto/issues/comments/112305466","html_url":"https://github.com/hohl/MIHCrypto/issues/29#issuecomment-112305466","issue_url":"https://api.github.com/repos/hohl/MIHCrypto/issues/29","id":112305466,"user":{"login":"hohl","id":744417,"avatar_url":"https://avatars.githubusercontent.com/u/744417?v=3","gravatar_id":"","url":"https://api.github.com/users/hohl","html_url":"https://github.com/hohl","followers_url":"https://api.github.com/users/hohl/followers","following_url":"https://api.github.com/users/hohl/following{/other_user}","gists_url":"https://api.github.com/users/hohl/gists{/gist_id}","starred_url":"https://api.github.com/users/hohl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hohl/subscriptions","organizations_url":"https://api.github.com/users/hohl/orgs","repos_url":"https://api.github.com/users/hohl/repos","events_url":"https://api.github.com/users/hohl/events{/privacy}","received_events_url":"https://api.github.com/users/hohl/received_events","type":"User","site_admin":false},"created_at":"2015-06-16T06:08:27Z","updated_at":"2015-06-16T06:08:27Z","body":"Some other theory: Do you split your blocks into sizes of 1024 at server side and then encrypt it? Becuase a "}}