AES encryption / decryption iOs and .Net

I used CocoaSecurity and RNCryptor to encrypt an NSString in an iOs app, and on the server side (.NET) tried to decrypt it using one of the many features found on the internet with no luck. Also AES decrypts online tools, cannot decrypt.

Can anyone provide a working example of NSString encryption on iOS and decrypt it in .NET (VB or C #) using AES256?

+3


source to share


2 answers


If you are using RNCryptor on iOS to use .net RNCryptor-cs . RNCryptor is more than just encryption / decryption, it is a complete secure protocol, see RNCryptor-Spec for more details on RNCryptor protocol. RNEncryptor is actively supported.



CocoaSecurity , this is not scary but I would not use it, it uses SHA to get the encryption key from the password and not good, current practice is to use a key derivation function like PBKDF2 which is much more secure. You will need to conform to the .NET protocol and it is not detailed, you will need to read the code to figure it out. It hasn't been updated in a year or more.

+1


source


Thanks zaf. Your answer helps me a lot.

As suggested, using RNCryptor on iOS and RNCryptor-cs on .Net I can encrypt data from iOS and then decrypt it on .Net.

Here's a small example of how I achieve this:

On the iOS side:



NSData* data = [@"mySecretMessage" dataUsingEncoding:NSUTF8StringEncoding];
NSError* error;
NSData* encrypted = [RNEncryptor encryptData:data
                                withSettings:kRNCryptorAES256Settings
                                    password:@"mySecretPassword"
                                       error:&error];
NSString* encryptedDataAsString = [encrypted base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithCarriageReturn];
//encryptedDataAsString = AwFnpL/jHjAYNkNnfBRUwl0pMwyHnM8uo2dojFk+rC7x9LnaFz+T1KaTjxSXoxF6Q4mzT+yl5RLuKZZuaiDlY5dXBw6TEyEXNJ8CxG9ZDZB3nQ==

      

In .Net (using Visual Basic):

Dim decryptor As RNCryptor.Decryptor = New RNCryptor.Decryptor

MessageBox.Show(decryptor.Decrypt("AwFnpL/jHjAYNkNnfBRUwl0pMwyHnM8uo2dojFk+rC7x9LnaFz+T1KaTjxSXoxF6Q4mzT+yl5RLuKZZuaiDlY5dXBw6TEyEXNJ8CxG9ZDZB3nQ==", "mySecretPassword"))
//MessageBox output = mySecretMessage

      

+2


source







All Articles