V
V
vitaliyharchenko2015-02-19 09:21:01
PHP
vitaliyharchenko, 2015-02-19 09:21:01

How to make AES 256 encoding and decoding in Objective C similar to php functions mcrypt_decrypt and mcrypt_encrypt?

For authorization to work in the application, it is necessary to carry out encryption and decryption. There is an equivalent in PHP. I can't fully debug work on Obj C.
PHP equivalent:

$pass = "user3";
$rnd_encoded = "CzN5txPZjwyfG2/YhQ8ddqpGDIY8meeW2oZL9+Rvbzp4B1UBVsOCsTFqGJ528TfX";
\\ Взяты переменные для дебага
$md5pass = md5($pass); // returns "92877af70a45fd6a2ed7fe81e1236b78"
$rnd = hash_dec($rnd_encoded, $md5pass); // returns "78f8aceb24b60fb12990397f52a62067"
$pass_encoded = hash_enc($pass, $rnd); // returns "MDAiXmrNM7W6j8EPi1l6uuJqEZID7Q7BFWbcW23ADEQ="

Code on SandBox
On Objective C I use the RNCryptor library:
NSString *md5pass = @"92877af70a45fd6a2ed7fe81e1236b78";
NSString *rndEncoded = @"CzN5txPZjwyfG2/YhQ8ddqpGDIY8meeW2oZL9+Rvbzp4B1UBVsOCsTFqGJ528TfX";
NSData *data = [rndEncoded dataUsingEncoding:NSUTF8StringEncoding];

NSError *error;
NSData *decryptedRnd = [RNDecryptor decryptData:data
                                          withPassword:md5pass
                                                 error:&error];
NSLog(@"%@", [error localizedDescription]);
NSLog(@"%@",[[NSString alloc] initWithData:decryptedRnd encoding:NSUTF8StringEncoding]);

I get the error "Unknown header" at the output.
What is the error? Tell me please.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question