0

I created an as.net web api to receive users credentials to authenticate. In my iOS app I am sending the username and password to the url. I only want to encrypt the password.

How to send an encrypted password that I can then decrypt it in asp.net?

My code:

NSString *username = Username.text;
NSString *password = Password.text;

NSData *dataToEnc = [Password.text dataUsingEncoding:NSUTF8StringEncoding];
NSData *encryptedData = [dataToEnc AES256EncryptWithKey:password];

NSURL *urlFormat = [NSURL URLWithString:[API_LOGIN stringByAppendingFormat:@"%@/%@",username, encryptedData]];
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:urlFormat cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:60];
NSData *returnData = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:nil error:nil];
NSString *responseString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];

This does not work.

Program_ming
  • 95
  • 2
  • 2
  • 9

1 Answers1

0

Typically you would base64 encode binary data in an http request.

NSString *encoded = [encryptedData base64EncodedStringWithOptions: NSDataBase64Encoding64CharacterLineLength];
KirkSpaziani
  • 1,962
  • 12
  • 14