1

I am using the AES encryption using the below code,

NSString *encryptedString =  [AESCrypt encrypt:@"str" password:@"password"];

The same string is not decoded correctly in .net server. The code is being used in .net server is as below,

AesEncryption = new RijndaelManaged();
AesEncryption.KeySize = 256;
AesEncryption.BlockSize = 128;
AesEncryption.Mode = CipherMode.CBC;
AesEncryption.Padding = PaddingMode.PKCS7;
string keyStr = "cGFWDwzc3dvcmQAAAAAAwzc3==";
string ivStr = "aEdcGFzc3dvcmQwzc3AvcmQAAAAA==";
byte[] ivArr = Convert.FromBase64String(keyStr);
byte[] keyArr = Convert.FromBase64String(ivStr);
AesEncryption.IV = ivArr;
AesEncryption.Key = keyArr;

Can you please help me on this.

Artjom B.
  • 61,146
  • 24
  • 125
  • 222

4 Answers4

0

Have you try below code for EncodeToPercentEscapeString to encrypt you string.

-(NSString *) encodeToPercentEscapeString
{
    return (__bridge_transfer NSString *) CFURLCreateStringByReplacingPercentEscapes(NULL,
                                                                            (CFStringRef) self,
                                                                            ((CFStringRef) @" !*'();:@&=+$,/?%#[]"));
}

NSString *password = @"password_123";
NSString *encryptString = [password encodeToPercentEscapeString];
Yalamandarao
  • 3,852
  • 3
  • 20
  • 27
0

We do have AES , SHA , MDM5 etc encryption techniques available in iOS to encrypt the data/strings for ensuring the security of data transmit over the air,

Specifically i prefer to use AES 256 encryption you can follow the tutorial for encryption of your string given in the URL : http://robnapier.net/aes-commoncrypto

Once you encrypted your string , you can send that to .net/ back end using web service.

To send the data to .net using web service the answer with 3 reputations in the question here : Send parameters to a web service will help you.

Community
  • 1
  • 1
iShwar
  • 1,625
  • 1
  • 16
  • 31
0

For a starter, you mixes up iv and key:

                                        VVVVVV
byte[] ivArr = Convert.FromBase64String(keyStr);
byte[] keyArr = Convert.FromBase64String(ivStr);
                                         ^^^^^^
Ebbe M. Pedersen
  • 7,250
  • 3
  • 27
  • 47
0

Use the below link: Add iOS files and implement the same provided in the header files and ask your .Net developer to work on the same.

https://github.com/Pakhee/Cross-platform-AES-encryption

Bharath
  • 190
  • 7