Encryption mismatch b/w iOS and C#

148 views
Skip to first unread message

Rahim K.

unread,
Mar 19, 2015, 5:59:57 PM3/19/15
to rncr...@googlegroups.com

Hi

I am testing the RNCryptor lib for a project. Basically we will be encrypting the data on iOS client and then decrypting on the .NET server. For my test to ensure its working, I am trying to encrypt a string in iOS and C# but get different results. The code snippet is below for both:

C#
string s = "this is a test";
RNCryptor.Encryptor en = new Encryptor();
en.TextEncoding = System.Text.Encoding.UTF8; // I tried all kinds of encoding but no luck
 string enc = en.Encrypt(s, "0x100001");

Result: AgEIqMSdKGo8US1nTSVoHOcqf94mzuYbB7NOyB1Mppa0fELEw868kX6YVpIywZVdxTAUafVu7FfTlrzUDVXc4XSn3QWc3vSxAXSxDQtNAZuW2g==


iOS

NSData *data = [@"this is a test" dataUsingEncoding:NSUTF8StringEncoding];
NSError *error;
NSData *encryptedData = [RNEncryptor encryptData:data
                                     withSettings:kRNCryptorAES256Settings
                                     password:@"0x100001"
      error:&error];
Result:
AwETKDI+AhqRFxUn0zKnoQL9oDx+Nf4/NwtTcnZcN/OpopBgwQ8Qy5nXwM9VDdOMRlmqJUCgYMs6hGzga0K7/yMGXlipfk1nYPhn4hJs2uKyzA==

Can you guys please let me know where the problem is? I expect it to produce the same encrypted string but its not. I would appreciate a quick response as we need to decide on the library.

Thanks

Rahim

Rob Napier

unread,
Mar 19, 2015, 6:01:10 PM3/19/15
to rncr...@googlegroups.com
By design, every encryption will return a different result. This is a security feature, implemented by the injection of several random numbers in the protocol.

-Rob

--
You received this message because you are subscribed to the Google Groups "rncryptor" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rncryptor+...@googlegroups.com.
Visit this group at http://groups.google.com/group/rncryptor.
For more options, visit https://groups.google.com/d/optout.



--
Rob Napier
Cocoaphony blog -- http://robnapier.net/blog
iOS Programming Pushing the Limits -- http://robnapier.net/book

Rahim Khatri

unread,
Mar 19, 2015, 6:26:27 PM3/19/15
to rncr...@googlegroups.com
Thank you for the response. That's what I was thinking as I was able to decrypt the string correctly on the other side.

Rahim
Reply all
Reply to author
Forward
0 new messages