简体   繁体   English

AES加密/解密iOs和.Net

[英]AES encryption/decryption iOs and .Net

I used CocoaSecurity and RNCryptor to encrypt NSString on iOs app, and on the server side (.NET) tried to decrypt it using one of the many function found on the web, but no luck. 我使用CocoaSecurity和RNCryptor来加密iOs应用程序上的NSString,并且在服务器端(.NET)尝试使用Web上发现的许多功能之一来解密它,但没有运气。 Also AES decryption online tools, fail to decrypt. AES解密在线工具也无法解密。

Can somebody provides a working example of NSString encryption on iOS and decryption of it in .NET (VB or C#) using AES256? 有人可以在iOS上提供NSString加密的工作示例,并使用AES256在.NET(VB或C#)中对其进行解密吗?

Thanks zaph. 谢谢zaph。 Your answer helps me a lot. 你的回答对我很有帮助。

As suggested, using RNCryptor on iOS and RNCryptor-cs in .Net I am able to encrypt data from iOS and then decrypt them on .Net. 如建议的那样,在iOS上使用RNCryptor和在.Net中使用RNCryptor -c我能够从iOS加密数据,然后在.Net上解密它们。

Here a small example, how I achieve that: 这是一个小例子,我是如何实现的:

On iOS side: 在iOS方面:

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==

On .Net side (using Visual Basic): 在.Net端(使用Visual Basic):

Dim decryptor As RNCryptor.Decryptor = New RNCryptor.Decryptor

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

If you are using RNCryptor on iOS for .net use RNCryptor-cs . 如果您在iOS上使用RNCryptor for .net请使用RNCryptor-cs RNCryptor is more than just encrypt/decrypt, it is a complete secure protocol, see RNCryptor-Spec for details on the RNCryptor protocol. RNCryptor不仅仅是加密/解密,它是一个完整的安全协议,有关RNCryptor协议的详细信息,请参阅RNCryptor-Spec RNEncryptor is being actively maintained. RNEncryptor正在积极维护。

CocoaSecurity it is not terrible but I would not use it, it uses SHA to derive the encryption key from from a password and that is not good, the current practice is to use a key derivation function such as PBKDF2 which is much more secure. CocoaSecurity并不可怕,但我不会使用它,它使用SHA从密码中导出加密密钥,这是不好的,目前的做法是使用密钥派生函数,如PBKDF2,它更安全。 You will have to match the protocol on .NET and that is not detailed, you will have to read the code to figure it out. 您必须匹配.NET上的协议,并且不详细,您必须阅读代码才能弄明白。 It has not been updated in a year or more. 它在一年或更长时间内没有更新。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM