RSA encryption with given modulus and exponent values in Objective-C -


i have modulus , exponent , have rsa encrypt plain text public key.

how generate public key 2048 bits length given modulus , exponent values in objective-c. have tried openssl throwing exception "the data decrypted exceeds maximum modulus of 256 bytes"

below code far have tried. didn't find option set key size 2048.

-(nsstring*)performrsaencryptionfordata:(nsstring *)plaintext withmodulus:(nsstring*)mod andexponent:(nsstring*)exp{  //plaintext = @"abcd";  nsmutablestring *hexmod = [nsmutablestring string]; nsmutablestring *hexexp = [nsmutablestring string]; const char* utf8mod = [mod utf8string]; const char* utf8exp = [exp utf8string];  while ( *utf8mod ) [hexmod appendformat:@"%02x" , *utf8mod++ & 0x00ff]; while ( *utf8exp ) [hexexp appendformat:@"%02x" , *utf8exp++ & 0x00ff];  const char *plain = [plaintext utf8string];  //char crip[]=""; rsa * pubkey = rsa_new(); bignum * modul = bn_new(); bignum * expon = bn_new();  bn_hex2bn(&modul, [hexmod utf8string]); bn_hex2bn(&expon, [hexexp utf8string]);   pubkey->n = modul; pubkey->e = expon;  int rsa_length = rsa_size(pubkey); unsigned char *crip[rsa_length];// =(unsigned char*)malloc( rsa_length ) ; //unsigned char *crip = (unsigned char*)malloc(rsa_length);   nsstring *s= [[nsstring alloc] init]; nsdata* data;  int irsaret = rsa_public_encrypt(strlen(plain), (const unsigned char *) plain,  (unsigned char *)crip, pubkey, rsa_pkcs1_oaep_padding ); if (irsaret<=0) {     nslog(@"error encrypt");     s= @""; } else {     nslog(@"%lu",sizeof(crip));     data = [nsdata datawithbytes:crip length:sizeof(crip)];     //data = [nsdata datawithbytes:(const void *)crip length:256];     s=[data base64encoding];     nslog(@"generated token: %@",s);   }  return s; 

}


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -