Skip to content Skip to sidebar Skip to footer

Generate Same Encrypted String Aes/cbc/pkcs7padding In Objective C, .net And Android

I want to generate the same encrypted string in iOS, android in .net. I can generate same string android and in .net but different for Objective C. Android code: public static Stri

Solution 1:

Thank you, Rob. I used the RNCryptor library for both (Objective C and C#) and it solved my problem.

Here is my code for Objective C:

-(NSString *)encryptUsingRNCryptor:(NSString *)strPassword{

NSData *data = [strPassword dataUsingEncoding:NSUTF8StringEncoding];
NSError *error;
NSData *encryptedData = [RNEncryptor encryptData:data
                                    withSettings:kRNCryptorAES256Settings
                                          password:kKeyForEncryption
                                             error:&error];
NSString *encryptString = [encryptedData base64EncodedStringWithOptions:0];

NSLog(@"enccrypted data ----->>>## %@ ## %@", encryptedData, encryptString);

// DecryptionNSData *decryptedData = [RNDecryptor decryptData:encryptedData
                                    withPassword:kKeyForEncryption
                                           error:&error];
NSString *decodedString = [[NSString alloc] initWithData:decryptedData encoding:NSUTF8StringEncoding];

NSLog(@" Decryted data ----%@ --------and string %@", decryptedData, decodedString);

return [encryptedData base64EncodedStringWithOptions:0];

}

and for C# decryption we used RNCryptor-cs library.

Once again thank you Rob :)

Post a Comment for "Generate Same Encrypted String Aes/cbc/pkcs7padding In Objective C, .net And Android"